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.
The HTML <audio> controls attribute is used to specify the control to play audio. It is the Boolean value. This attribute is new in HTML5.
The <source> element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format. The text between the <audio> and </audio> tags will only be displayed in browsers that do not support the <audio> element.
The <audio> tag references one or more audio files with a src attribute or the <source> element. The browser will choose the first file with a file format that it supports. Supported audio file formats include MP3, WAV, and OGG.
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);
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With