发生的事情是它一遍又一遍地重复一些 1
全局变量:
var song1 = new Audio("songs/loop1.mp3");
var song2 = new Audio("songs/loop2.mp3");
var song3 = new Audio("songs/loop3.mp3");
var song4 = new Audio("songs/loop4.mp3");
var song5 = new Audio("songs/loop5.mp3");
var song6 = new Audio("songs/loop6.mp3");
var song7 = new Audio("songs/loop7.mp3");
var song8 = new Audio("songs/loop8.mp3");
var song9 = new Audio("songs/loop9.mp3");
var song10 = new Audio("songs/loop10.mp3");
var song11 = new Audio("songs/loop11.mp3");
var songList = [];
var currentSong = 1;
songList.push(song1,song2,song3,song4,song5,song6,song7,song8,song9,song10,song11);
var song = songList[0];
在游戏循环之前,我调用:
song.play();
听众:(我觉得这与相同的 var 保持一致,并且不会像数组中新 var 的歌曲点一样向上移动?)
song.addEventListener('ended', NextSong);
它调用:
function NextSong()
{
currentSong++;
if(currentSong > songList.lenght);
{
currentSong = 1;
}
song.play();
}