Looping Video at some videotime or cuepoint?

How can i loop a video when the video has 10 sec at the end and i need to jump in video at time 7 sec for my loop?

Is it possible?

ty.
paul

Hi Paul!

EDIT: Replaced previous code in this post. This code is placed in the “Scene Load” handler.

function loopVid(hypeDocument, element, event) {
      var vid = hypeDocument.getElementById('myVideo');
      vid.addEventListener('timeupdate', function() {
      var videoCurrentTime = vid.currentTime;
      if (videoCurrentTime >= 7) { // set loop at 7 seconds
          vid.currentTime = 0;
	}	
    });
}

VideoLoop.hype.zip (2.5 MB)

Hi Scott,

ty for this nice work!!!

What am i doing wrong? Do i need both scripts in the file?

Or only this one posted in your message?

Ty
Paul

Ok, it works.

BUT if the video has 11 sec and i want it to loop at the end of the video then it does nothing.

How can i trigger the end of the video sequence?

Ty.

Do i need both scripts in the file? Or only this one posted in your message?

Only the currently posted one. The other one belongs in the dustbin of history.

BUT if the video has 11 sec and i want it to loop at the end of the video then it does nothing.
How can i trigger the end of the video sequence?

Just change the time in the code:

if (videoCurrentTime >= 7) { // set loop at 7 seconds

If You want it to loop at 11 seconds change the "7" to "11".


And, as with so many coding scenarios, there is another way to do things. You can loop based on when the video itself ends, which would be the case for your quoted post above.

For triggering an action (such as looping) based on when a video~audio ends check out:

Using this approach You can simply lay in the script without hard coding the video duration. Note the vid.addEventListener uses 'ended' instead of 'time update' in the example below.


Example:

function loopVid(hypeDocument, element, event) {
      var vid = hypeDocument.getElementById('myVideo');
      vid.addEventListener('ended', function() {  
      vid.play();
  });
}
1 Like

Great!!! Ty it works. :slight_smile: