2014-10-22 138 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