Crafty
Crafty copied to clipboard
AddEventListen on error in the audio function
The only event that gets listen to is the canPlayThrough
event. Crafty should also listen to the Error event, as there can be several reasons why a audio element does not load.
https://github.com/craftyjs/Crafty/blob/develop/src/loader.js#L198
What is the error event? Is it stalled?
I think it just Error, but haven't had time to test.
http://stackoverflow.com/questions/13614803/how-to-check-if-html5-audio-has-reached-different-errors
https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events
But stalled
seems pretty describing also too, hence the description: "The user agent is trying to fetch media data, but data is unexpectedly not forthcoming."
Hmm, we do actually listen to the error event for audio. We always reach the line obj.onerror = err
. (It's outside of the media type if
blocks.)
I can maybe be that the onerror function is attached too late. http://stackoverflow.com/a/10791300/804984
The event handler must be attached before the browser fires the error event, which is why the example sets the src attribute after attaching the handler. http://api.jquery.com/error/
But when i try that myself, it works fine setting it afterwards: http://jsfiddle.net/3vxCu/32/
But in this example the onerror function does not fire, even through the file does not exist: http://jsbin.com/IqArecAB/1/edit