似乎在为<source>
标记引入<audio>
元素之前,当音频出现错误时,您可以在audio.error.code
中看到错误代码。但是,这似乎不再发生了。由于错误事件现在仅在子<source>
元素上触发,而不再在音频标记上触发,因此音频标记不再具有error
属性(它始终为空)。源标记也不会获得错误属性。
您可以在此jsFiddle中看到这一点。
如果音频标签没有获得错误属性,您认为如何检测错误类型?似乎这是每个浏览器中的错误。
答案 0 :(得分:2)
onerror将会触发。
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);
答案 1 :(得分:1)
在Angular中,您可以触发此事件以了解aodio是否加载。
this.audio.addEventListener('error', ()=> {
console.log("could not load audio source");
///Do your thing
});