Last active
May 22, 2024 04:27
-
-
Save rhom6us/fc7dabfc214ae7ea9d531e0a4e29fac3 to your computer and use it in GitHub Desktop.
simple song transition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var songInfos = [{ | |
url: "https://fuckingdj.blob.core.windows.net/test/Swedish%20House%20Mafia%20-%20Save%20The%20World%20(Zedd%20Remix).mp3", | |
}, { | |
url: "https://fuckingdj.blob.core.windows.net/test/Jewelz%20%26%20Scott%20Sparks%20feat.%20Quilla%20%E2%80%93%20Unless%20We%20Forget%20(Original%20Mix).mp3", | |
}]; | |
var song1toSong2TransitionData = { | |
startTime: 72.556, | |
skipBeginning: 45.824, | |
}; | |
var context = new AudioContext(); | |
function loadSong(url) { | |
return fetch(url) | |
.then(function (response) { return response.arrayBuffer(); }) | |
.then(function (arrayBuffer) { return context.decodeAudioData(arrayBuffer); }) | |
.then(function (audioBuffer) { | |
var sourceNode = context.createBufferSource(); | |
sourceNode.buffer = audioBuffer; | |
sourceNode.connect(context.destination); | |
return sourceNode; | |
}); | |
} | |
Promise.all(songInfos.map(({url})=>loadSong(url))) | |
.then( ([song1, song2]) => { | |
var now = context.currentTime; | |
song1.start(now); | |
song2.start(now + song1toSong2TransitionData.startTime, song1toSong2TransitionData.skipBeginning); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment