Chrome html5 video buffered.end事件 [英] chrome html5 video buffered.end event

查看:514
本文介绍了Chrome html5 video buffered.end事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测视频文件何时完成加载。我使它在firefox和safari上成功运行,但是在chrome上,缓冲事件表现得很奇怪。
所以,
在我的本地主机chrome中工作正常,但是当我上传到服务器时;

I'm trying to detect when a video file has completed loading. i made it work successfully on firefox and safari but on chrome, buffered event behaves strange.. so, in my local host chrome works fine but when i upload to server;


  1. 当页面刷新时,缓冲区百分比停止在%50左右,但是缓冲区为%100,

  1. buffer percentage stops about %50 but buffers %100,

,百分比停留在%0,但它继续缓冲。

when page refreshed, percentage stay at %0 but it continues to buffering..

这是我的javascript

here is my javascript

function loaded()
        {
            var v = document.getElementById('myVideo');
            var r = v.buffered;
            var total = v.duration;
            var current=v.currentTime;
            var start = r.start(0);
                    var end = r.end(0); 
            var downloadPercent= Math.round((end / total)*100)
            $("#loadProgress").css('width',downloadPercent+ '%');

                    if(downloadPercent==100){
                $("#preloaderWrapper").fadeOut(function(){
                document.getElementById('myVideo').play();
                clearInterval(ratoteLoad);
                $(this).remove();                   
                    });             
            }       

        }   

            $('#myVideo').bind('progress', function() 
            {
                loaded();
            });

有什么想法吗?
谢谢

any idea? thank you

推荐答案

试试这个:

try this instead:

myVideoTag = document.getElementById('video');
myVideoTag.addEventListener('progress', function(e) {
    var percent = null;
    // FF4+, Chrome
    if (myVideoTag && myVideoTag.buffered && myVideoTag.buffered.length > 0 && myVideoTag.buffered.end && myVideoTag.duration) {
        percent = myVideoTag.buffered.end(0) / myVideoTag.duration;
    } 
    // Some browsers (e.g., FF3.6 and Safari 5) cannot calculate target.bufferered.end()
    // to be anything other than 0. If the byte count is available we use this instead.
    // Browsers that support the else if do not seem to have the bufferedBytes value and
    // should skip to there. Tested in Safari 5, Webkit head, FF3.6, Chrome 6, IE 7/8.
    else if (myVideoTag && myVideoTag.bytesTotal != undefined && myVideoTag.bytesTotal > 0 && myVideoTag.bufferedBytes != undefined) {
        percent = myVideoTag.bufferedBytes / myVideoTag.bytesTotal;
    }

    if (percent !== null) {
        percent = 100 * Math.min(1, Math.max(0, percent));

        // ... do something with var percent here (e.g. update the progress bar)

    }

}, false);

...从mediaelement.js中复制的评论,代码也一样,但为了更易于显示,在此调整。我省略了Firefox 3.0的代码,因为它不太相关。
在所有当前浏览器中都能正常工作

... comments copied from mediaelement.js, code as well but adjusted for easier display here. I omitted the code for Firefox 3.0 as it's less than relevant. working fine in all current browsers

PS:thx给约翰戴尔mejs - 好东西;)

PS: thx to John Dyer for mejs - great stuff ;)

这篇关于Chrome html5 video buffered.end事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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