views:

54

answers:

1

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 play back to zero?

+4  A: 

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();
CMS