我创建了一个 javascript 来在音频结束后更改音频。
var songlist = new Array("a.mp3", "b.mp3", "c.mp3", "d.mp3", "e.mp3", "f.mp3");
var dir = "music/";
var curr_track = 0;
var isfirstrun;
function start()
{
if(curr_track == songlist.length)
curr_track = 0;
var track = document.getElementById('track');
track.innerHTML = curr_track;
var audio = document.getElementById('audio');
isfirstrun = true;
audio.src = dir+songlist[curr_track];
audio.load();
audio.play();
if(isfirstrun == true)
{
audio.addEventListener('ended', function(){ curr_track++; start();}, false);
isfirstrun = false;
}
}
在 HTML 内部,
<body onload="start();">
代码中track
使用的是显示当前轨道号是什么,我发现输出是
0 then 1 then 3 then 7
因此,它缺少c.mp3
,e.mp3
并且f.mp3
来自songlist
。
如何解决循环问题?