只有我的前 2 首歌曲正在播放,然后什么也没有发生。我不确定为什么它会工作两次然后停止?我希望它永远播放一系列歌曲。我也不能让我的倒带工作,我想要它,所以当你点击倒带按钮时,歌曲会转到数组上的 -- 如果小于 0,它会转到 array.length 歌曲。
全局变量:
var btnPlay = new Button(561,743,33,92);
var btnRewind = new Button(0,0,800,300); //entire canvas just to test
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 rewindClicked = false;
var songList = [];
var currentSong = 1;
songList.push(song1,song2,song3,song4,song5,song6,song7,song8,song9,song10,song11);
var song = songList[0];
快退按钮点击方法:
function mouseClickedButtons(e)
{
alert("hi"); //works
if(btnRewind.checkClicked())
{
alert("hey"); //does not
rewindClicked = true;
NextSong();
}
}
换歌方法:
function NextSong()
{
document.removeEventListener('ended',NextSong);
if(rewindClicked ==true)
{
currentSong--;
}
else
{
currentSong++;
}
if(currentSong > songList.length);
{
currentSong = 1;
}
if(currentSong < 0)
{
currentSong = songList.length;
}
songList[currentSong].play();
rewindClicked = false;
songList[currentSong].addEventListener('ended', NextSong);
}
听众:
song.addEventListener('ended', NextSong);
按钮对象(我有这个在播放按钮中工作,所以它可以工作)
function Button(xL,xR,yT,yB)
{
this.xLeft = xL;
this.xRight = xR;
this.yTop = yT;
this.yBottom = yB;
}
Button.prototype.checkClicked = function()
{
if(this.xLeft <= mouseX && mouseX <= this.xRight && this.yTop <= mouseY && mouseY <= this.yBottom)
{
return true;
}
}