2011-12-03 22 views
7

Bir video dosyasının yükleme işlemini tamamladığını tespit etmeye çalışıyorum. Ben itfaiyeci ve safari üzerinde başarılı bir şekilde çalıştım ama krom, tamponlu olay benim garip davranır .. , benim yerel host chrome çalışıyor ama ben sunucuya yüklediğinizde;chrome html5 video buffered.end olay

  1. tampon yüzdesi% 50 fakat tampon% 100 hakkında durur

  2. tazelenmiş sayfa,% 0 düzeyindeki yüzde kal ama ara belleğe devam .. Burada

benim 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(); 
      }); 

bir fikrin ? Eğer

cevap

7

yerine bu deneyin teşekkür:

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 kopyalanan yorum, kod yanı fakat düzeltilmiş için daha kolay görüntülenmesini burada. Firefox 3.0'ın kodunu, alakalı olandan daha az olduğu için ihmal ettim. tüm güncel tarayıcılarda iyi çalışıyor

PS: mejs John Dyer thx - büyük şeyler;)

+0

Yorumlarınız için teşekkür ederim, ben bu denedim ama benim için hala aynı görünüyor .. –

+0

Yorumunuz test diyor IE 7/8'de ancak bu tarayıcılar 'addEventListener' – AlienWebguy

+0

@AlienWebguy'yi kullanmadığından testin başarısız olacağını hayal ediyorum: utanç duyuyorum - thats true! myVideoTag.attachEvent ('progress', function (e) {...}) için ekstra yordamları ihmal ettim; –