Timeupdate不支持html5自动播放

时间:2017-05-24 03:35:50

标签: javascript jquery google-analytics html5-video video.js

我有一个使用video.js框架的html5视频,并使用GA进行分析,当我更改视频以自动播放timeupdate事件时,它没有被触发。我正在使用添加事件监听器来触发事件和开始/播放/暂停并结束工作正常但不是时间更新。我正在使用的代码在

之下
document.addEventListener('DOMContentLoaded', init, false);
var videoId, dur, quarter, stat;
videoId = document.getElementById('videojs-qualityselector-player');


function init () {
    videoId.addEventListener('play', videoStart, false);
    videoId.addEventListener('play', videoPlay, false);
    videoId.addEventListener('pause', videoPause, false);
    videoId.addEventListener('ended', videoEnd, false);
    videoId.addEventListener('timeupdate', videoTimeUpdate, false);
}

  function setKeyFrames (duration) {
    if(dur){return;}
    dur = duration;
    quarter = duration / 4;
  }


  function videoTimeUpdate () {
      var curTime = videoId.currentTime;
      if (curTime >= quarter && curTime < quarter * 2 && stat !== 1){
      console.log("25%");
      ga('send', 'event', 'video', '25% video played', 'label1');
        stat = 1;
      } else if (curTime >= quarter * 2 && curTime < quarter * 3 && 
        stat !== 2){
        console.log("50%");
        ga('send', 'event', 'video', '50% video played', 'label1');
        stat = 2;
      } else if (curTime >= quarter * 3 && curTime < dur && stat !== 3)
      {
         console.log("75%");
        ga('send', 'event', 'video', '75% video played', 'label1');
        stat = 3;
      }
  }

function videoStart () {
     console.log("start");
    ga('send', 'event', 'video', 'video started', 'label1');
    videoId.removeEventListener('play', videoStart, false);
    setKeyFrames(this.duration);
  }

  function videoPlay () {
     console.log("played");
    ga('send', 'event', 'video', 'video played', 'label1');
    setKeyFrames(this.duration);
  }

  function videoPause () {
    console.log("paused");
    ga('send', 'event', 'video', 'video paused', 'label1');
  }

  function videoEnd () {
    stat = 4;
     console.log("100%");
    ga('send', 'event', 'video', '100% video played', 'label1');
    videoId.addEventListener('play', videoStart, false);
   }

感谢

0 个答案:

没有答案