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?

Ron Zukerman
  • 61
  • 1
  • 8

2 Answers2

0

I solved it with the following solution. This is not documented and found by reverse engineering. It is all about accessing the html audio object, which is availalbe under _a.

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

The body of the method is based on this post about html5 stalled callback in safari

Community
  • 1
  • 1
Simon Fakir
  • 1,712
  • 19
  • 20
0

I can suggest a different "fix" I use with an html5 using platform (samsung smart TV):

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

This works since in html5, unlike flash, the 'readystate' property jumps from '0' to '3' almost instantanously, skipping '1'. ('cause if the track started buffering it's playable...).

Hope this works for you as well.