Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control HTML5 video player loop with JavaScript

I am looking to enable looping of HTML5 video in browsers that do not support the loop tag (ff) with JavaScript. Does anyone know the feasibility of accessing the end of the video play and reverting playback to zero?

like image 860
jeffreynolte Avatar asked Aug 11 '10 04:08

jeffreynolte


People also ask

How do I make a video repeatedly in HTML?

Autoplay is used to start the video when the video and page loads. The loop attribute is a boolean attribute. When present, it specifies that the video will start over again, every time it is finished. The loop attribute should do it.

How do you stop a video from looping in HTML?

Simply call jQuery and add your code before the closing tag and then add the class '. noloop' to the parent of the video element. It simply removes the attribute 'loop' from the video HTML and that allows the video to run to the end and stop without looping.


2 Answers

You can detect if the loop property is supported, and set it to true.

For browsers that don't support it, you can simply bind the ended media event, and start it over:

var myVideo = document.getElementById('videoId');
if (typeof myVideo.loop == 'boolean') { // loop supported
  myVideo.loop = true;
} else { // loop property not supported
  myVideo.addEventListener('ended', function () {
    this.currentTime = 0;
    this.play();
  }, false);
}
//...
myVideo.play();
like image 178
Christian C. Salvadó Avatar answered Sep 24 '22 04:09

Christian C. Salvadó


You can simply loop the video on or off through loop="false" for stopping auto video repeat play.

<iframe style="position: absolute; top: 0; left: 0;"
src="http://video/name.mp4" width="100%" height="100%" frameborder="0"  webkitallowfullscreen loop="true" controls="false" mozallowfullscreen allowfullscreen></iframe>

This loop="true" will enable video player loop.

like image 27
Bipul Roy Avatar answered Sep 21 '22 04:09

Bipul Roy