HTML5 Video not looping

后端 未结 5 1181
粉色の甜心
粉色の甜心 2021-02-04 19:09

I\'m having a weird problem. My two versions of chrome(regular & canary) refuse to loop the video i\'m showing. Or well, sometimes they loop it twice and stops after that. W

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 19:29

    For some reason I had issues with 'ended' event binding.

    Here is how I fixed it:

    1. removed 'loop' attr from video.
    2. added onended to invoke replay()

       <video autoplay='true' onended="replay()"></video> 
    3. defined replay() as below:

      function replay() {
          console.log('video ended');
          document.getElementsByTagName('video').currentTime = 0;
          document.getElementsByTagName('video')[0].play();
      }

提交回复
热议问题