Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop video with media fragments?

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?

like image 866
vantage5353 Avatar asked Apr 25 '14 22:04

vantage5353


1 Answers

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.

like image 190
chennighan Avatar answered Nov 15 '22 06:11

chennighan