只有前兩首歌曲在播放,所以沒有任何反應。 我不確定它爲什麼會兩次工作然後停下來?我希望它能讓玩家永遠經歷一連串的歌曲。 我無法讓我的倒帶也奏效,我想要它,所以當你點擊倒帶按鈕時,歌曲進入 - 對於數組,如果它小於0,它將進入array.length歌曲。html5音樂歌曲只播放前兩個數組?
全局:
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;
}
}
您應該讓您的代碼更具可讀性 - 線條之間的空間更少,正確縮進。這只是難以理解的 – jbkkd
你有沒有找到任何解決方案呢? –