0

I am looking for a way to check the IF statement every 1 second,

var vid = document.getElementById("video");
var cTime = vid.currentTime;
if ( cTime > 5 && cTime < 10) {
}

and once it is met, then run the code

  vid.currentTime = 15

I have tried setInterval method but assume that it is memory leak. The other thing I tried is

var vid = document.getElementById("video");
var cTime = vid.currentTime;
function skip() {
  if (cTime > 5 && cTime < 10) {
    vid.currentTime = 15
  }
  setTimeout(skip, 1000);
}

but it keeps on firing the currentTime to 15. I might have multiple if statements in the future. What is the best way to do it?

SarmadK
  • 123
  • 1
  • 2
  • 14

1 Answers1

1

Remove setTimeout(skip, 1000); from within your role and place in another part of the code where you make your call correctly.

var vid = document.getElementById("video");
var cTime = vid.currentTime;

setTimeout(skip, 1000);

function skip() {
  if (cTime > 5 && cTime < 10) {
    vid.currentTime = 15
  }
}
Renan Barbosa
  • 1,046
  • 3
  • 11
  • 31