How to use javascript to autoloop a video within a certain time range?

HTML portion for video:

<video muted="true" autoplay="true" class="vid" id="someVidName" >
    <source src="[replace]" type="video/mp4">
</video>

Javascript to make loop. Note that the movie will start from beginning and play until 3.5 sec, then will loop around 1.99 and 3.5 perpetually.

(function () {
    var vidElem = document.getElementById('someVidName');
    console.log(vidElem);
    vidElem.addEventListener("timeupdate", function () {
        if (vidElem.currentTime > 3.5) {
            vidElem.currentTime = 1.99;
            vidElem.play();
        }
    }, false);
})();

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>