Control HTML5 video player loop with JavaScript
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();