Reputation: 5891
It appears that before the <source>
element was introduced for <audio>
tags, when the audio had an error you could see the error code in audio.error.code
. However, this doesn't seem to happen anymore. Since the error events are now only fired on the child <source>
elements and no longer on the audio tag, the audio tag no longer has an error
property (it's always null). The source tags don't get an error property either.
You can see this in this jsFiddle.
How are you suppose to detect the error type now that the audio tag doesn't get an error property? It seems that this is bug in every browser.
Upvotes: 5
Views: 4513
Reputation: 25
In Angular you can fire this event to know if aodio did load or not.
this.audio.addEventListener('error', ()=> {
console.log("could not load audio source");
///Do your thing
});
Upvotes: 2
Reputation: 207511
onerror will fire if you add true after the function.
var audio = document.getElementById('audio');
audio.addEventListener('error', function(e) {
var noSourcesLoaded = (this.networkState===HTMLMediaElement.NETWORK_NO_SOURCE);
if(noSourcesLoaded) console.log("could not load audio source");
}, true);
Upvotes: 6