2

I'm trying to to write a javascript app that use the [SoundManager 2][1] api and aim to run in all desktop and mobile browsers. On the iPad platform, Soundmanager is using the HTML5 audio api since there is on flash support. Now, when I'm trying to play two audio files back to back, both loaded in response to a click event, a [HTML5::stalled][2] event is occasionally raised. How do I set an event handler to catch the stalled event?

Since sound objects in my app are created on the fly and I don't know how to access directly to tags that are created by SoundManager, I tried to use a delegate to handle the stalled event:

    document.delegate('audio', 'stalled', function (event) {...});

It doesn't work. the event did not raised in respond to stalled. (I had an alert in my handler).

Also tried to use [Sound::onsuspend()][3] to listen for stalled, but onsuspend pops out on the end of sound::play(). How can we distinguish between stalled and other events that may raise the audio::suspend? Is there any other way to access the tags that SoundManager must create in order to play HTML audio?

4

2 回答 2

0

我用以下解决方案解决了它。逆向工程没有记录和发现这一点。这完全是关于访问 html 音频对象,该对象位于 _a 下。

currentSound = soundManager.createSound({..});
currentSound._a.addEventListener('stalled', function() {
     if (!self.currentSound) return;
    var audio = this;
    audio.load();
    audio.play();
});

该方法的主体基于this post about html5stalled callback in safari

于 2014-12-15T19:54:07.950 回答
0

我可以建议使用 html5 平台(三星智能电视)使用不同的“修复”:

var mySound = soundManager.createSound({..});  
mySound.load();  
setTimeout(function() {
    if (mySound.readyState == 1) {
        // this object is probably stalled
        }
}, 1500);

这是因为在 html5 中,与 flash 不同,“readystate”属性几乎瞬间从“0”跳到“3”,跳过“1”。(因为如果轨道开始缓冲它是可播放的......)。

希望这也适用于你。

于 2015-06-14T19:57:45.547 回答