vendredi 25 septembre 2015

How do I pause an HTML video and resume automatically over a loop?

I have a 4 second long video embedded in my HTML page using video tag. I need to pause the video for 2 secs first at 2.99s, 3.44s and then at 4.00s. For that to happen the video needs to resume from previous instance.

But after long hours of effort I haven't been able to find a solution. Thus far I have just been able to get the video paused for >=2.99s but it does not resume even after I had used setInterval function.

Here is the code:

var vTag = document.getElementById('video');

setInterval(function() { pVideo();}, 2000);

function pVideo() {
      vTag.ontimeupdate = function(e) {
      cTime = vTag.currentTime;
      (cTime >= 2.9 || cTime >= 3.44 || cTime >= 4.00) ? vTag.pause(): vTag.play();
 };
};

PS: The video is being used as a background video for header section.




Aucun commentaire:

Enregistrer un commentaire