简体   繁体   中英

Looping through a locally stored video in HTML with JavaScript

So, I am trying to have a video playing and looping the whole time within my HTML page. I added the

<video src="img/Pexels Videos 2169880_Trimmed_Trimmed.mp4" autoplay loop muted playsinline></video>

autoplay loop within the HTML file and it still isn't looping through the video. Does anyone have any idea of how to loop through this video via JavaScript? I've tried various different functions but none of them have been working.

<video id="video" src="img/Pexels Videos 2169880_Trimmed_Trimmed.mp4" autoplay loop muted playsinline></video>
<script>
var video = document.getElementById('video')
// When the 'ended' event fires
video.addEventListener('ended', function(){
  // Reset the video to 0
  video.currentTime = 0;
  // And play again
  video.play();
});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM