2014-10-22 44 views
0

我製作了一個循環低谷視頻的視頻滑塊。我在編寫代碼時曾多次測試代碼,但是一週後,當我在線設置內容時,它不再運行。HTML5 video addEventListener'ended'not fired

的問題是什麼:

火狐>做工精細,使用addEventListener被調用,一切都很好 Chrome瀏覽器>工作正常,沒有錯誤,但的addEventListener不叫,週期不會持續。

這是一個常見的Chrome錯誤,還是我錯誤我自己的代碼?

,我已經創建的週期是這個>

/* SLIDER */ 
var counter = 0; 
var vid_count = 2; 
var logotime = 2000; 
var waittime = 5000; 

function mainRotation(index){ 

    loadVideo(index); 
} 
function loadVideo(index){ 
    var video = document.getElementById('slideVideo' + index); 
    if(video.getAttribute("src")==null) { 
     video.setAttribute("src", './templates/tacticalghillies/video/slidevideo_' + index + '.mp4'); 
     video.load(); 
    } 
    else{ 
     video.currentTime = 0; 
     $('#slideVideo' + index).show(); 
    } 

    $('#slideImage').addClass('fadeout'); 
    var timing = setInterval(function(){ 
     showVideo(index, function(){ 
      if(counter < vid_count-1){ 
       counter++; 
       mainRotation(counter); 
      } 
      else{ 
       mainRotation(counter); 
       counter = 0; 
      } 

     }); 
     clearInterval(timing); 

    }, waittime) 


} 

function showVideo(index, cb){ 
    //fade in video opacity 

    //play video 
    //video ended: 
    var video = document.getElementById('slideVideo' + index); 
    video.play(); 
    console.log("playing"); 
    video.addEventListener('ended', myHandler, false); 
    function myHandler(e){ 
     if(!e) { e = window.event; } 
     console.log("eddd"); 
     $('#slideImage').removeClass('fadeout'); 
     var timer = setInterval(function() { 
      clearInterval(timer); 
      $('#slideVideo' + index).hide(); 
      cb(); 
     }, logotime); 

    } 

} 

只是要清楚這是一個以這段代碼corrosponds的HTML:

  <div class="animation"> 
      <img class="a_aligned" id="slideImage" src="./images/slide_holder.png"> 
      <video class="a_aligned slideVideo" width="1280" style="max-width:1280px;" id="slideVideo0" ></video> 
      <video class="a_aligned slideVideo" width="1280" style="max-width:1280px;" id="slideVideo1" ></video> 
      <img class="a_aligned" style="z-index:-1;" src="./images/slide_overlay.png"> 
     </div> 

回答

1

完全相同這裏的問題...還沒有找到如何解決這種情況。 有關信息,這個完全相同的代碼昨天運行良好。它的發生,當我更新了Chrome瀏覽器的版本38.0.2125.104

其實我確切的代碼是:

$(videoBack).on("ended", function(){ [...] 

編輯:因爲我做了一個演示做,我用速戰速決,但我仍然有了解Chrome爲何不再參加結束活動。

快速修復:

setTimeout(function(){ [...] }, 1400); 
+0

謝謝您的repsonse,好知道我不是唯一一個有這個問題。 – 2014-10-23 11:16:52