Search code examples
audioerror-handlingloadingcreatejs

How to catch loading errors with soundjs "createjs.Sound.registersound"?


Using, for instance, SoundJS 0.5.2, in a browser like Firefox, I'm fine loading files that exist. Not so good recovering from loading files that don't exist or have other problems It seems that registerSound won't tell me there's a problem. Maybe I'm just not asking nicely.

For example,

    createjs.Sound.addEventListener( "fileload", function () {
        console.log( "it loaded" ) ;
    } ) ;
    createjs.Sound.registerSound( 'http://xx.yy.zzz/missing.ogg', 'foo' ) ;

Works fine, printing "it loaded" if I point to a URL that loads correctly, but where is the hook I can use to catch the case when I'm trying to load a non-existent file? Or handle some other error? I'm not worried about exotic things like a file taking a long time to load... I'd be happy just catching the case of a 500 response that comes back immediately.

I'm hoping there's an "onerror" handler to register somewhere and I'm just too dense to find it.


Solution

  • the intention with internal SoundJS loading was to give very simple loading with no extra features. Its built on the assumption that everything will work, and in the case of failure it will fail silently. For more complex loading, we recommend using PreloadJS.

    Hope that helps.