How to stop playing a <video> element and return it back to its original state?

前端 未结 2 726
别跟我提以往
别跟我提以往 2021-01-28 14:36

I was wondering how I could go about resetting a video that was playing or paused to its original state where it isn\'t playing? I know you can pause the video, but what I reall

相关标签:
2条回答
  • 2021-01-28 15:13

    You may want to consider using an API for this: have a look at VideoJS

    Otherwise try adding the controls Attribute on your video Tag

    0 讨论(0)
  • 2021-01-28 15:20

    The easiest way I have been able to find is to reset the source of the video on the ended event so that it returns to the beginning. The other way to handle it would be to have a div with the poster image in that you swap out for the video, but this is simpler...

    <script>
    var vid=document.getElementById('myVideo');
    vid.addEventListener("ended", resetVideo, false);
    
    function resetVideo() {
        // resets the video element by resetting the source
        this.src = this.src
    }
    </script>       
    
    0 讨论(0)
提交回复
热议问题