Firefox不识别视频src是否被中断 [英] Firefox doesn't recognize if video src gets interrupted

查看:129
本文介绍了Firefox不识别视频src是否被中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩video.js,使视频观看更可靠。目前的情况是:在观看视频时,连接中断(互联网连接中断)。



使用chrome是没有什么大不了的:我创建了一个函数,附加函数的错误事件和瞧,如果发生错误,我的功能能够恢复(在这种情况下,它只是试图重新加载视频,并寻求到最后一个已知的位置)。

在Firefox上什么也没有发生。错误永远不会被提出。
我试着解决这个问题,并注意到firefox似乎认为该文件是完全加载的情况下,网络中断。所以bufferedPercent跳转到1,并且loadedalldata事件也被触发。对我来说,这似乎是刚刚打破,但我无法把它钉在一个Firefox或video.js的问题。



其他人有这样的问题或知道一个更好的方法来处理这样的问题?

背景信息:为了测试的情况下,我运行两个运行nginx谁提供视频文件的Web服务器的HAProxy盈方。触发我的问题,我只是杀死当前正在交付流的nginx。所以重新连接应该可以正常工作(只要另一个仍然在工作;)

感谢和问候,
Darkman

解决方案

难道是你绑定视频标签上的错误,而不是源标签?
正如这里所述:


不是将错误事件分派给媒体元素本身,而是将其传递给与导致错误的源对应的子元素。



 < video controls id =videoTagwidth =640height =360 preload =auto> 
< source src =pathto.mp4type ='video / mp4; codecs =avc1.42E01E,mp4a.40.2'id =mp4Source>
< source src =pathto.webmtype ='video / webm; codecs =vp8.0,vorbis'id =webmSource>
< / video>
< script type =text / javascript>
document.getElementById('mp4Source')。addEventListener('error',function(ev){
alert('mp4Source error');
},false);
document.getElementById('webmSource')。addEventListener('error',function(ev){
alert('webmSource error');
},false);
document.getElementById('videoTag')。addEventListener('error',function(ev){
alert('videoTag error');
},false);
document.getElementById('videoTag')。addEventListener('stalled',function(ev){
alert('videoTag stalled');
},false);

< / script>

编辑:还会检查停滞的事件,媒体资源正在下载时的网络。



当在HTML5视频中检测到播放/网络错误时,我通常会使用一些在 section
谢谢


i'm currently playing around with video.js to make video watching a bit more reliable. The current case if: while watching a video, the connection gets interrupted (loss of internet connectivity).

With chrome it was no big deal: I created a function, attached the function to the error event and voila, if an error occurred, my function was able to recover (in this case its just trying to reload the video and seek to the last known position).

On firefox nothing happened at all. The error is never raised. I tried to work around this a bit and noticed that firefox seems to think the file is fully loaded in case of a network interruption. So the bufferedPercent jumps to 1 and the loadedalldata event is also triggered. For me this seems to be just broken, but i'm unable to nail it down to a firefox or a video.js problem.

Anyone else having such problems or knows a better way to handle such problems?

Background info: to test the case, i run a HAProxy infront of two webservers running nginx who deliver the video files. To trigger my problem, i just kill the nginx which is currently delivering the stream. So a reconnect should work fine (as long as the other one is still working of course ;)

Thanks and regards, Darkman

解决方案

Could it be that you are binding the error on the video tag and not the source tag? As stated here:

Instead of the error event being dispatched to the media element itself, it now gets delivered to the child elements corresponding to the sources resulting in the error.

<video controls id="videoTag" width="640" height="360" preload="auto">
<source src="pathto.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' id="mp4Source">
<source src="pathto.webm" type='video/webm; codecs="vp8.0, vorbis"' id="webmSource">
</video>
<script type="text/javascript">
document.getElementById('mp4Source').addEventListener('error', function(ev) {
alert('mp4Source error');
}, false);
document.getElementById('webmSource').addEventListener('error', function(ev) {
alert('webmSource error');
}, false);
document.getElementById('videoTag').addEventListener('error', function(ev) {
alert('videoTag error');
}, false);
document.getElementById('videoTag').addEventListener('stalled', function(ev) {
alert('videoTag stalled');
}, false);

</script>

EDIT: also check for the stalled event as it triggers when one disconnects the network while the media resource is downloading. Source.

When detecting playback/network errors on HTML5 video I normally use something that follows the code at end of this section. Thanks

这篇关于Firefox不识别视频src是否被中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆