I'm a beginner of Javascript. And I'm trying to do a little project that can play array audio files sequently. The code below are inside of annyang API. My idea is to wait for 10 seconds after say some certain words and play the first element in the array, and then wait for 10 seconds, play the second element of the array, and so on so forth. Thus, I use the for loop, but I don't why, it always plays the 'oh_interesting_why' which is the third element.
var playList = ["tell_me_more", "why", "oh_interesting_why"];
var dir = "sound/";
var extention = ".wav";
var i;
var agent = navigator.userAgent.toLowerCase();
if (agent.indexOf('firefox') != -1 || agent.indexOf('opera') != -1) {
extention = ".wav";
}
//audio = new Audio();
for (i = 0; i < playList.length; i++) {
audio = new Audio();
//audio = dir + playList[i] + extention;
audio.src = dir + playList[i] + extention;
audio.load();
setTimeout(function() {
audio.play();
}, 10000);
}
audio.loop = false;
I have been struggling with is for 2 days. Can't figure out why. I'm open to use jQuery, Javascript, or HTML5. Please help me!! Thank you in advance.