简体   繁体   English

检测html5视频上的错误

[英]detect an error on html5 video

I am trying to detect when there is an error on playing a video in html5. 我正在尝试检测何时在html5中播放视频时出现错误。

To be more specific, My use case is when one is trying to play an HLS video in MAC (so "canPlayType" is at least "maybe") - yet for some reason the video does not play. 更具体地说,我的用例是当尝试在MAC中播放HLS视频时(因此“ canPlayType”至少为“也许”),但由于某种原因该视频无法播放。

I have tried listening to 'error' event on the video tag. 我尝试收听视频标签上的“错误”事件。 Doesn't work. 不起作用 In fact, the 'error' event is not even firing if I use an invalid url source! 实际上,如果我使用无效的URL源,甚至不会触发“错误”事件! (See a demo here: http://mockup.on.aol.com/yogev/hls.html ) (在此处查看演示: http : //mockup.on.aol.com/yogev/hls.html

Could anyone please help? 谁能帮忙吗?

Thanks! 谢谢!

You should add error event listener before you set the source of the video. 在设置视频源之前,应添加错误事件侦听器。 So, if you add this after your error listener, you will get error callback: 因此,如果在错误侦听器之后添加此代码,则会得到错误回调:

document.getElementsByTagName('video')[0].src='https://someFalseurl.mp4';

Your current demo page is creating error listener after the error has already passed. 错误过去后,您当前的演示页面将创建错误侦听器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM