1、主要利用Audio的监听事件addEventListener,监听到声音播放结束ended,播放下一个文件
audio.addEventListener('ended', function () { console.log('音频播放结束'); });
2、示例:
var voiceList = ['1.wav','2.wav','3.wav'] var voiceIndex= 0; var audio = new Audio(); function payNext(){ if(voiceIndex >= voiceList.length){ audio.pause(); //暂停 voiceList = []; voiceIndex = 0; } audio.src = voiceList[voiceIndex]; audio.play(); voiceIndex += 1; //下一个音频 audio.addEventListener('ended',payNextVoice,false); //播放结束调自己 }
标签:voiceIndex,Audio,voiceList,js,列表,addEventListener,播放,audio From: https://www.cnblogs.com/handsomeziff/p/17934586.html