【发布时间】:2013-02-19 04:29:32
【问题描述】:
我想通过在每个函数中使用.play() 执行函数调用后备来播放连续的声音序列,以逐个播放声音。
最有趣的是: 每次在我的 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个回调...只是刷新网页后不同...
-
拜托,DRY 绝对不需要 5 个几乎相同的函数,更不用说事件监听器的杂耍了。
-
您的 iPad 是哪一代以及您运行的是哪个 iOS?
-
Sorry Cerbrus:真的是因为每次回调都会随机停止所以我添加了它们进行测试,抱歉代码长...
标签: javascript jquery html ipad html5-audio