Reputation: 741
I have three sound objects :
sound_a = new Audio("a.mp3");
sound_b = new Audio("b.mp3");
sound_c = new Audio("c.mp3");
I want to play the sound b when the sound a is finished. And play the sound c when the sound b is finish.
How I can do that ?
My code is the following :
sound_a.pause();
sound_a.currentTime = 0;
sound_a.play();
sound_b.pause();
sound_b.currentTime = 0;
sound_b.play();
sound_c.pause();
sound_c.currentTime = 0;
sound_c.play();
Upvotes: 0
Views: 73
Reputation: 25034
the easiest way to do it would be, keep a single audio object, array of sources, listen to end event and play:
let i = -1, sources =[...], a= new Audio(), playNext= e => {
i++;
if(!sources[i]) return;
a.src=sources[i];
}
a.autoplay = true;
a.onended = playNext;
playNext();
Upvotes: 1