Crafty icon indicating copy to clipboard operation
Crafty copied to clipboard

AddEventListen on error in the audio function

Open kevinsimper opened this issue 10 years ago • 5 comments

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

kevinsimper avatar Jan 15 '14 10:01 kevinsimper

What is the error event? Is it stalled?

starwed avatar Jan 15 '14 14:01 starwed

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

kevinsimper avatar Jan 15 '14 17:01 kevinsimper

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."

kevinsimper avatar Jan 15 '14 17:01 kevinsimper

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.)

starwed avatar Jan 16 '14 15:01 starwed

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

kevinsimper avatar Jan 16 '14 16:01 kevinsimper