Js实现video自动跳转到上次观看的位置、获取视频总时长

2020-09-03 10:34:43 浏览数 (1)

代码语言:javascript复制
 <video id="myvideo" controls>
      <source
        src="https://vdse.bdstatic.com//b84fba2d24e31318aea3b215b0d394a9?authorization=bce-auth-v1/fb297a5cc0fb434c971b8fa103e8dd7b/2017-05-11T09:02:31Z/-1//243721300cb13899ad3f3b37abde401c8aafdb6c21222eedf75ba61771ae42d4"
        type="video/mp4"
      />
    </video>
代码语言:javascript复制
  $(document).ready(function () {
      var myvideo = document.getElementById("myvideo");
      // 获取视频观看进度
      myvideo.addEventListener("timeupdate", function () {
          console.log(myvideo.currentTime)
      });
      // 让视频观看到第10s
      myvideo.currentTime = 10;
      //获取视频的总长度
      console.log(myvideo.duration)
  })

0 人点赞