Firefox没有';t点火错误事件在<;音频>;标记或显示回退文本

Firefox没有';t点火错误事件在<;音频>;标记或显示回退文本,firefox,cross-browser,html5-audio,Firefox,Cross Browser,Html5 Audio,我正在使用,如果或标记无法播放媒体,将调度错误事件。它还将逐个检查嵌套在媒体标记中的标记(或其他标记,最后一条可能是错误消息),直到找到可以使用的标记。这些似乎都不适合我;不会对元素触发错误事件,也不会显示错误消息。我做错了什么?我找到的解决方法是: var audioTag = document.createElement("audio"), sourceTag = document.createElement("source"); //Add error event listene

我正在使用
,如果
标记无法播放媒体,将调度
错误事件。它还将逐个检查嵌套在媒体标记中的标记(
或其他标记,最后一条可能是错误消息),直到找到可以使用的标记。这些似乎都不适合我;不会对元素触发错误事件,也不会显示错误消息。我做错了什么?

我找到的解决方法是:

var audioTag = document.createElement("audio"),
    sourceTag = document.createElement("source");

//Add error event listeners for browsers other than FF
audioTag.onerror = function() {
    console.log("file can't be played. error from audio tag");
}
sourceTag.onerror = function() {
    console.log("file can't be played. error from source tag");
}
//The only way to tell that file failed to play on FF
//Timeout is because audioTag.networkState === audioTag.NETWORK_NO_SOURCE
//on IE till it starts downloading the file
setTimeout(function() {
    if(audioTag.networkState === audioTag.NETWORK_NO_SOURCE) {
        console.log("this hack is only for <audio> on FF.");
        console.log("Not for <video> and on no other browsers");
    }
}, 3000);
sourceTag.src = "<file_url>";
audioTag.appendChild(sourceTag);
var audioTag=document.createElement(“音频”),
sourceTag=document.createElement(“源”);
//为FF以外的浏览器添加错误事件侦听器
audioTag.onerror=函数(){
console.log(“文件无法播放。音频标记出错”);
}
sourceTag.onerror=函数(){
log(“无法播放文件。源标记出错”);
}
//唯一能告诉你该文件在FF上播放失败的方法
//超时是因为audioTag.networkState===audioTag.NETWORK\u无\u源
//直到它开始下载文件
setTimeout(函数(){
if(audioTag.networkState===audioTag.NETWORK\u无\u源){

console.log(“此黑客攻击仅针对,但错误事件触发正常。我猜我错了;或者它在FF14(我当时正在使用)上被破坏,因为错误事件在我的应用程序中也触发正常。谢谢@BorisZbarsky

我找到的解决方法是:

var audioTag = document.createElement("audio"),
    sourceTag = document.createElement("source");

//Add error event listeners for browsers other than FF
audioTag.onerror = function() {
    console.log("file can't be played. error from audio tag");
}
sourceTag.onerror = function() {
    console.log("file can't be played. error from source tag");
}
//The only way to tell that file failed to play on FF
//Timeout is because audioTag.networkState === audioTag.NETWORK_NO_SOURCE
//on IE till it starts downloading the file
setTimeout(function() {
    if(audioTag.networkState === audioTag.NETWORK_NO_SOURCE) {
        console.log("this hack is only for <audio> on FF.");
        console.log("Not for <video> and on no other browsers");
    }
}, 3000);
sourceTag.src = "<file_url>";
audioTag.appendChild(sourceTag);
var audioTag=document.createElement(“音频”),
sourceTag=document.createElement(“源”);
//为FF以外的浏览器添加错误事件侦听器
audioTag.onerror=函数(){
console.log(“文件无法播放。音频标记出错”);
}
sourceTag.onerror=函数(){
log(“无法播放文件。源标记出错”);
}
//唯一能告诉你该文件在FF上播放失败的方法
//超时是因为audioTag.networkState===audioTag.NETWORK\u无\u源
//直到它开始下载文件
setTimeout(函数(){
if(audioTag.networkState===audioTag.NETWORK\u无\u源){

log(“此黑客攻击仅针对,但错误事件在那里触发OK。我猜我错了;或者它在FF14(我当时正在使用)上被破坏了),因为错误事件在我的应用程序中也可以触发。谢谢@BorisZbarsky

如果使用会发生什么?很可能在添加OneError的脚本运行时错误事件已经触发…不可能。我在设置
source
标记.update的
src
属性之前添加了
OneError
事件侦听器正在编辑代码以反映这一点。对于
视频
标记,事件在其他浏览器上启动得很好,而对于
音频
标记,事件在FF上启动得不好。这很奇怪。是否可以在显示问题的页面上发布链接?不幸的是,没有。这是一项工作,目前正在开发中。我已经找到了一个解决方法(基于超时后检查音频元素的networkState属性),我将在下面发布,一旦我验证了它的工作情况。如果使用会发生什么?很可能在添加OneError的脚本运行时错误事件已经触发…不可能。在设置
标记的
src
属性之前,我添加了
onerror
事件侦听器。更新代码以反映此错误s、 对于
视频
标记,该事件在其他浏览器上启动得很好,但是对于
音频
标记,该事件在FF上启动得不好。这很奇怪。是否可以在显示问题的页面上发布链接?不幸的是,没有。这是一项工作,目前正在开发中。我找到了一个解决方法(基于超时后检查音频元素的networkState属性),一旦我验证了它的工作状态,我将在下面发布。
var audioTag = document.createElement("audio"),
    sourceTag = document.createElement("source");

//Add error event listeners for browsers other than FF
audioTag.onerror = function() {
    console.log("file can't be played. error from audio tag");
}
sourceTag.onerror = function() {
    console.log("file can't be played. error from source tag");
}
//The only way to tell that file failed to play on FF
//Timeout is because audioTag.networkState === audioTag.NETWORK_NO_SOURCE
//on IE till it starts downloading the file
setTimeout(function() {
    if(audioTag.networkState === audioTag.NETWORK_NO_SOURCE) {
        console.log("this hack is only for <audio> on FF.");
        console.log("Not for <video> and on no other browsers");
    }
}, 3000);
sourceTag.src = "<file_url>";
audioTag.appendChild(sourceTag);