[英]I need to play next song when click on on-click button
var song1 = $('#sound-1');
var song2 = $('#sound-2');
var audioArray = [song1, song2];
var i=0;
var lastPlayedFile = null;
$(".click").click(function(){
if(lastPlayedFile !== null) {
lastPlayedFile[0].currentTime = 0;
lastPlayedFile.trigger('pause');
}
if (i< audioArray.length){
lastPlayedFile = audioArray[i];
audioArray[i].trigger('play');
i++;
} else if (i>=audioArray.length){
i = 0;
lastPlayedFile = audioArray[0];
audioArray[i].trigger('play');
};
});
該代碼對我不起作用,我正在使用firefox Web瀏覽器。 這段代碼有什么問題嗎?
請確保您使用的是正確<audio>
和所示的標簽在這里 。 瀏覽器將選擇第一個可識別的源:
<audio controls> // browser tries to fetch horse.ogg first <source src="horse.ogg" type="audio/ogg"> // browser tries to fetch horse.mp3 if the above couldn't be recognized <source src="horse.mp3" type="audio/mpeg"> // if none files are valid the browser falls back with a message Your browser does not support the audio element. </audio>
還請確保您嘗試訪問的文件確實存在。 我嘗試找到它們,但是得到了404響應。
此外,這行代碼不會執行任何操作:
lastPlayedFile[0].currentTime = 0;
請確保你有一個currentTime
屬性集在每個的audioArray
元素( song1
和song2
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.