0

发生的事情是它一遍又一遍地重复一些 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();

}
4

1 回答 1

1

song.play()您的NextSong功能更改为songList[currentsong].play()

lenght改为length

你可以让你的函数代码更漂亮

function nextSong{
    currentSong = (++currentSong)%songList.length;
    songList[currentsong].play();
}

编辑

如果您需要开始循环所有歌曲。在您的代码中,它接缝第一个被调用一次,只有其他人在循环中 (0, 1, 2, ..., 10, 1, 2, 3...)

于 2013-06-30T05:21:32.373 回答