为了使HTML5动画在idevice上播放声音,我将整个浏览器的大小设为div,命名为“ theScreen”,并使用以下代码:

audioCont.prototype.iCrapLoadPlayThrough = function () {
    if (this.supported) {
        theScreen = document.getElementById("theScreen");
        var self = this;
        theScreen.addEventListener('touchstart', function(){self.iCrapClickedLoadPlayThrough();}, false);
        return(1);
    } else {
        return(0); // Not supported
    }
};
audioCont.prototype.iCrapClickedLoadPlayThrough = function () { // Check if supported, then load the audio file
    var self = this;
    theScreen.removeEventListener('touchstart', function(){self.iCrapClickedLoadPlayThrough();}, false);
    this.addCanPlayThrough();
    this.load();
}


现在可以使用了,当用户在屏幕上点击时,声音/动画就会开始。问题是,如果他们再次点击它,声音就会停止,并且每次重复点击都会听到几毫秒的音频。有人知道为什么吗?

最佳答案

它不是删除事件侦听器,因为它是一个匿名函数。删除匿名函数,仅使用函数名

 theScreen.addEventListener('touchstart',self.iCrapClickedLoadPlayThrough,false)
 theScreen.removeEventListener('touchstart',self.iCrapClickedLoadPlayThrough,true)

关于javascript - 触摸iPad/iPhone设备上的HTML5音频会停止,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7814994/

10-10 21:04