Play full HTML5 video and then loop a section of it

后端 未结 5 1148
不知归路
不知归路 2021-02-05 15:20

I\'m trying to play an 8.6 second video once completely, and then loop a small section of the video infinitely, to keep the illusion of a never-ending video. So far I\'ve looked

5条回答
  •  佛祖请我去吃肉
    2021-02-05 15:51

    Your code is fine, the problem is with your MP4 file! Try using a much smaller video like this one ( http://www.w3schools.com/tags/movie.mp4 ) to confirm the issue is not with your code.

    So how can you achieve the same result but with large videos files? You will need two video files:

    • video1 is the main video
    • video2 is the looping video

    Remember: HTML5 video has no problem playing and looping large video files so we will use this method to play the videos.

    In the example below we will play the first video and when it finishes we will execute a function to hide video1 and then show/play video2. (Video 2 is already set to loop)

    Don't forget to load JQuery in your head otherwise this will not work.

    
    
    
    
    
    
     
    

提交回复
热议问题