What's the best method that allows returning an array of audio sources (via AJAX), and having them play sequentially? ie: play the audio file, wait for it to end, play the next.
Thanks
It is currently Sat Dec 02, 2017 4:22 pm Advanced search
files = "one,two,three,four";
function sequence(files){
var arr = files.split(",");
var audio = new Audio('sounds/'+arr[0]+'.ogg');
var audio1 = new Audio('sounds/'+arr[1]+'.ogg');
var audio2 = new Audio('sounds/'+arr[2]+'.ogg');
var audio3 = new Audio('sounds/'+arr[3]+'.ogg');
function play2(){
audio1.play();
}
function play3(){
audio2.play();
}
function play4(){
audio3.play();
}
audio.addEventListener('ended', play2, false);
audio1.addEventListener('ended', play3, false);
audio2.addEventListener('ended', play4, false);
audio.play();
}
var files = "one,two,three,four".split(',');
var audios = [];
for (var i = 0; i < files.length; ++i) {
audios.push(new Audio('sounds/'+files[i]+'.ogg');
if (i < files.length - 1)
audios[i].onended = playNext;
}
var j = 0;
function playNext() {
j++;
audios[j].play();
}
audios[0].play();
var files = "one,two,three,four".split(',');
var audios = [];
for (var i = 0; i < files.length; ++i) {
audios.push(new Audio('sounds/'+files[i]+'.ogg'));
if (i < files.length - 1)
audios[i].onended = playNext;
}
var j = 0;
function playNext() {
j++;
audios[j].play();
}
audios[0].play();
audios[i].addEventListener('ended', playNext, false);
var files = "one,two,three,four".split(',');
var audios = [];
for (var i = 0; i < files.length; ++i) {
audios.push(new Audio('sounds/'+files[i]+'.ogg'));
if (i < files.length - 1)
audios[i].addEventListener('ended', playNext, false);
}
var j = 0;
function playNext() {
j++;
audios[j].play();
}
audios[0].play();
That's a bug in Firefox.LFReD wrote:Your example only plays the first file. The audios[i].onended event isn't firing.
Users browsing this forum: No registered users and 0 guests