我想播放的歌曲只有當用戶按下'播放'按鈕,如何在不刷新網頁的情況下播放歌曲?
沒有等待加載所有的21首歌曲。
當我按下按鈕'播放'頁面跳起來像刷新一樣,這是不正常的。
我可以做些什麼來改善我的代碼。
請嘗試播放example site中的歌曲並查看問題。
非常感謝。
var Music = {
init:function(){
song = new Audio();
//speaKer = document.getElementById("imgSpeaker");
this.volume = 0.08;
this.isMute = false;
canPlayMP3 = (typeof song.canPlayType === "function" && song.canPlayType("audio/mpeg") !== "");
song.src = canPlayMP3 ? "http://rafih.co.il/wp-content/uploads/2013/07/1.mp3" : "http://rafih.co.il/wp-content/uploads/2013/07/1.ogg";
song.preload = 'auto';
},
/* start:function(){
song.src = canPlayMP3 ? "http://rafih.co.il/wp-content/uploads/2013/07/1.mp3" : "http://rafih.co.il/wp-content/uploads/2013/07/1.ogg";
song.volume = 0.08;
song.autoplay = true;
song.load();
},*/
play: function() {
song.volume = 0.08;
song.autoplay = true;
song.load();
// Music.speaker();
},
stop: function() {
if (!song.ended) {
song.pause();
}
},
next: function() {
if (curr < count) {
curr++;
}else curr = 1;
song.src = canPlayMP3 ? "http://rafih.co.il/wp-content/uploads/2013/07/" + curr + ".mp3" : "http://rafih.co.il/wp-content/uploads/2013/07/" + curr + ".ogg";
},
};
function load() {
Music.init();
}
你可能要考慮使用jPlayer的html5音頻。它有一些很好的內置功能。我不確定當文件播放完畢播放下一個文件時是否可以附加事件。 jPlayer將允許你在文件停止播放的時候附加一個事件 –