I am trying to loop a video URL(with media fragments) when it gets paused. I set up a listener to call a loopVideo() function when the video gets paused:
function loopVideo() {
var video = document.getElementById('Video1');
var videoFile = 'file1.mp4#t=10,10';
video.src = videoFile;
video.play();
};
document.getElementById('Video1').addEventListener('paused', loopVideo(), false);
So far the video fragment plays once, but doesn't loop when it pauses. Is there an error in my code or are media fragments the problem?
This is 2 years later but I'm going to post this because I just ran into this issue recently. Basically What I did was I dynamically got the values in the media fragments and then in my timeupdate
video event listener checked whether the current time was greater than the upper bound of the media fragment. If it was greater than the upper bound, I set the current time to the lower bound and play the video. Here's the code I used:
function checkMediaFragmentBounds(video, x,y) {
if(video.currentTime > y) {
video.currentTime = x;
video.play();
}
}
And then here's a working JSFiddle: JSFiddle where you can also see my logic for getting the bounds of the media fragment. Hope this helps someone else looking for this answer because that's how I found this was looking for an answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With