I can't make the video to loop after 2 seconds. It should loop after the video pauses. I'm not sure hot to make it happen. The functionality works fine, but doesn't loop.
function playVideo() {
var starttime = 0; // start at 0 seconds
var endtime = 2; // stop at 2 seconds
var video = document.getElementById('videoElm');
video.addEventListener("timeupdate", function() {
if (this.currentTime >= endtime) {
this.pause();
// SHOULD LOOP HERE?
}
}, false);
//suppose that video src has been already set properly
video.load();
video.play();
try {
video.currentTime = starttime;
} catch (ex) {
//handle exceptions here
}
}
playVideo();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<video id="videoElm" autoplay muted controls loop>
<source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/webm">
</video>
</div>