Javascript function not fired on video timeupdate -


currently working on page containing video has paused @ points (like chapters). made function stop video when hits next "time marker" looks this:

function vidpause(nextmarker){    var timemarker = nextmarker;      if(videoplayer.currenttime >= timemarker) {      videoplayer.pause();      videoplayer.removeeventlistener('timeupdate', vidpause());    }  };

and i'm trying fire way:

videoplayer.addeventlistener('timeupdate', vidpause(nextmarker));

but seems fire when video loaded. nothing happens when video playing (tested using console.log(videoplayer.currenttime); inside vidpause function).

note: need function called way can remove event listener when hits time marker, way won't stop when user wants play video point on.

thanks in advance suggestions!

the function being called once in addeventlistener line, that's not passing callback.

try this:

function videoupdate(e) {   vidpause(nextmarker, videoplayer.currenttime;); // call function }  function vidpause(nextmarker, timestamp){   var timemarker = nextmarker;    if (timestamp >= timemarker) {     videoplayer.pause();     videoplayer.removeeventlistener('timeupdate', videoupdate);   } };  videoplayer.addeventlistener('timeupdate', videoupdate); // note no brackets, it's passing ref function rather calling 

i don't know scope of nextmarker is, should able start console logging , find out.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -