SoundManager on 100% HTML5 mode stuck on "stalled"

577 views Asked by At

In my Smart-TV app, I'm using the SoundCloud API, through Cross Domain Request - $.getJSON() etc.
The app also uses the SoundManager2 API on a 100% HTML5 mode (no Flash) to load tracks from the .stream_url retrieved from SoundCloud. The problem begins when trying to play the loaded tracks. Say the app loaded 10 tracks, some of them won't play.
I noticed the log stating:

0040  sound0: play(): Loading - attempting to play...
0041  sound0: abort
0042  sound0: waiting
0043  sound0: loadstart
0044  sound0: stalled 

Where it stays forever. The issue always happens for the same tracks, while other tracks are streamable, and playable, showing the log:

0078  sound2: durationchange (191190)
0079  sound2: loadedmetadata
0080  sound2: stalled
0081  sound2: suspend
0082  sound2: loadeddata
0083  sound2: canplay
0084  sound2: onload()
0085  sound2: playing ♫

The code used to create a sound object, and play it:

        SoundObject = soundManager.createSound({    //  load the current track
            url: "https://api.soundcloud.com/tracks/" + TrackIDs[elements][index-1] + "/stream?client_id=f430822ab78177a5cfb94d572d9036a2",
            volume: 100,
            autoLoad:    true, 
            //autoPlay:      true,
            //stream:        true,
            whileplaying:function(){currentPosition=SoundObject.position;barWhilePlaying(elements, index, currentPosition);},                         
            onfinish:    function(){barOnFinish(elements, index);},                       
            onstop:      function(){barOnStop(elements, index);},
        });
        SoundObject.play();

(Where whileplaying, onfinish, and onstop parameters all call a function that changes the css and/or the classes of elements within the html document.)

My questions:

  1. Is there a way to know beforehand that a SMsound object won't play?
  2. Say I can't know before loading it that it will "loadstart" and "stall" forever, is there a way of knowing that after it was loaded?
    I'm asking this since some of the tracks will load and play after long periods of time.
1

There are 1 answers

0
Yehuda Shaoshvili On BEST ANSWER

I can suggest a work-around that may help.

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

This works since in html5, unlike flash, the readystate property jumps from '0'(uninitialized - not yet loaded) to '3'(loaded) almost instantanously, skipping '1'(initialized - started loading), cause if the sound started buffering it's playable in html5, hence readystate returns 3...
On html5, permanently (or for a long duration) stalled sounds will have their readystate = 1 long after the load() attempt.

after that - you can replace/remove/skip the errouneous track or whatever.

  • Note - 5500 msec's should be long enough, you can play around with it and see what is the best timeOut for your platform.

Hope this help you.