chrome html5 video buffered.end事件

Bah*_*dır 7 javascript video html5 buffer google-chrome

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

  1. 缓冲区百分比大约停止%50但缓冲区%100,

  2. 当页面刷新时,百分比保持在%0但它继续缓冲..

这是我的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();
            });
Run Code Online (Sandbox Code Playgroud)

任何的想法?谢谢

Jör*_*eld 7

试试这个:

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);
Run Code Online (Sandbox Code Playgroud)

...从mediaelement.js复制的注释,代码也进行了调整,以便在此处更容易显示.我省略了Firefox 3.0的代码,因为它不太相关.在所有当前浏览器中正常工作

PS:对于约翰戴尔来说,对于mejs来说很棒 - 很棒的东西;)