0

I want to accurately jump to the specific time of my video-tag and pause at the specific endpoint in the video.

let's say I have a simple function for it: myDuration(5, 9) it'll play video from the second 5 and will pause the video when it reaches second 9.

so far I can start the video from the accurate start point but it seems that I can not listen for endpoint and pause the video at exactly second 9.

I think the problem is that I cannot track the current time of the video accurately here in the code and that causes the problem:

if (myVideo[0].currentTime == b) {
                myVideo[0].pause();
 }

sometimes it pauses at second 10 and sometimes it pauses at second 8 ...??? Why?

How to track the endpoint or listen for the endpoint accurately?

Here is the code:

    var myVideo = document.getElementsByTagName('video');

    // I want to start from second 5 of the video
    myDuration(5, 9);

    function myDuration(a, b) {

    myVideo[0].currentTime=a;

    myVideo[0].play();

    // I want to pause at exactly second 9 of the video so I listen for it
    myVideo[0].addEventListener("timeupdate", function() {
           if (myVideo[0].currentTime == b) {
                myVideo[0].pause();
            }
        }, false);

    }
Sara Ree
  • 3,417
  • 12
  • 48

0 Answers0