我想在每一個功能的做函數調用回退與.play()
由1連續HTML5音頻.play(),只有第1次觸發
最有趣的播放聲音1播放連續的聲音序列是: 每次在iPad設備上播放時都會有不同的聲音表現。 * 有時播放音頻3次,有時4次,甚至只有1次! *
只有iPad中的「突然停止問題」,在我的谷歌瀏覽器上沒問題。
它不是iPad上的自動播放的問題,我想怎麼我已經在第一時間觸發...
請看看,並有一個測試的iPad也許並請幫助...
的Html - 身體:
<audio id="html5soundtag">
<source src="1.mp3" type="audio/mpeg">
</audio>
<a href="javascript://" onClick="playhtml5sound1('1.mp3')">aaaa</a>
的Javascript:
var audioPath ="";
var audioElement = document.getElementById('html5soundtag');
function playhtml5sound1(filename){
audioPath = filename;
audioElement.src = audioPath;
audioElement.src = audioPath
audioElement.load()
audioElement.play();
audioElement.addEventListener("ended",soundcallback1);
};
var soundcallback1 = function(){
alert("1st");
audioElement.removeEventListener("ended",soundcallback1);
playhtml5sound2("1.mp3");
}
function playhtml5sound2(filename){
audioPath = filename;
audioElement.src = audioPath;
audioElement.src = audioPath
audioElement.load();
audioElement.play();
audioElement.addEventListener("ended",soundcallback2);
};
var soundcallback2 = function(){
alert("2nd");
audioElement.removeEventListener("ended",soundcallback2);
playhtml5sound3("1.mp3");
}
function playhtml5sound3(filename){
audioPath = filename;
audioElement.src = audioPath;
audioElement.src = audioPath
audioElement.load();
audioElement.play();
audioElement.addEventListener("ended",soundcallback3);
};var soundcallback3 = function(){
alert("3rd");
audioElement.removeEventListener("ended",soundcallback3);
playhtml5sound4("1.mp3");
}
function playhtml5sound4(filename){
audioPath = filename;
audioElement.src = audioPath;
audioElement.src = audioPath
audioElement.load();
audioElement.play();
audioElement.addEventListener("ended",soundcallback4);
};var soundcallback4 = function(){
alert("4th");
audioElement.removeEventListener("ended",soundcallback4);
playhtml5sound5("1.mp3");
}
function playhtml5sound5(filename){
audioPath = filename;
audioElement.src = audioPath;
audioElement.src = audioPath
audioElement.load();
audioElement.play();
audioElement.addEventListener("ended",soundcallback5);
};var soundcallback5 = function(){
alert("5th");
audioElement.removeEventListener("ended",soundcallback5);
playhtml5sound6("1.mp3");
}
function playhtml5sound6(filename){
alert("This is End. " + filename);
}
你使用1.MP3只?有6種不同的回調?你打算玩1.mp3,2.mp3等? –
是的,對於測試,我只使用單個樣品聲音「1.mp3」,因爲現在我的問題是回調將突然死亡(停止)在iPad上運行時...和每次不同的時間「死」 !例如,將只有2次回調運行,下次運行完畢,然後下一次運行1次回調...刷新網頁後僅有不同... – user1900121
請[DRY](http: //en.wikipedia.org/wiki/Don't_repeat_yourself) 絕對沒有必要有5個非常相同的功能,更不用說事件監聽器雜耍了。 – Cerbrus