音频文件数组
var musicArr = new Array('xxx.mp3',xxx1.mp3'');
方法一:[简单粗暴]
直接调用 palyTest(0,musicArr);
function playTest(i,arr) { if(i == arr.length) { $("#audio_list").empty(); return false; } $("#audio_list").append("<audio id=\"audioList_"+i+"\" src="+arr[i]+" />"); var tt = document.getElementById("audioList_"+i); tt.play(); tt.addEventListener('ended', function () { i++; playTest(i,arr); }, false); }
方法二:[粗暴简单]
调用playMusic(musicArr);
function playMusic(arr){ var repeat = 0; var myAudio = new Audio(); myAudio.preload = false; myAudio.controls = true; myAudio.hidden = true; var src = arr.pop(); myAudio.src =src; myAudio.addEventListener("ended",playEndedHandler,false); myAudio.play(); myAudio.loop = false; function playEndedHandler(){ if(repeat >= arr.length){return false;} src = arr.pop(); myAudio.src = src; arr.unshift(src); myAudio.play(); repeat++; } }
So 无注释 不代码