Issue setting currentTime in HTML5 video

后端 未结 4 473
清酒与你
清酒与你 2020-12-11 14:40

I have a video in the middle of my html. As you can see at first I haven\'t any source

4条回答
  •  一生所求
    2020-12-11 15:23

    As above mentioned, you try to set currentTime when the video is not seekable. So, as an alternative use-case (reset time to 0 when a user click on a button, for example), you can do something like:

    function resetVideo() {
      myVid.pause();
       
      if (myVid.seekable.length > 0) {
        myVid.currentTime = 0;
      }
    }

    Alternatively, you can also trying to reset only if the video has been played before.

    function resetVideo() {
      myVid.pause();
       
      if (myVid.currentTime !== 0) {
        myVid.currentTime = 0;
      }
    }

提交回复
热议问题