如何从视频标签错误事件中获取字符串/消息或代码?

时间:2012-07-24 20:50:37

标签: javascript video html5-video

所以这感觉就像一个愚蠢的问题。希望我只是忽略了一些显而易见的事情,但我正在倾听视频元素的错误。错误字符串实际显示在控制台中,并且错误事件正常触发,但是当我浏览错误对象时,我似乎无法在任何地方找到该字符串。我的目标是简单地记录此错误以用于记录目的。另一种选择是获取错误代码 - 任何可以记录的内容都可以为我们的调试器提供关于实际问题的线索。知道如何从视频标签错误对象中获取错误字符串或代码吗?

代码:

$(this.video)
    .on( 'error', this.proxy(this.onVideoError));

onVideoError : function(e) {
  console.log(e, " the e");
  console.log(e.toString());//prints [object Object]
  console.log(e.code, " the code");// prints undefined
},

1 个答案:

答案 0 :(得分:0)

在我的错误处理程序中,我使用的是err.nameerr.message成员。 由于错误实际上没有PHP或其他语言的代码,您可能需要解析消息和名称以创建自己的代码。

var errorHandler = function(err) {

  // prints the name of the error
  console.log(err.name);

  // prints the description that is also shown in the error console
  console.log(err.message);

  // this works only in some browsers
  // line and stack are not supported by all vendors
  console.log(err.line, err.stack);
}