javascript - currentTime not working as intended. I'm not getting something here -
i not understand why this:
myvid1=document.getelementbyid("video1"); var trigger = 5; var timecheck = myvid1.currenttime; if(timecheck==trigger){ alert("awesome"); }; does not work. certainly @ 5 seconds if statement should trigger? mean, don't why won't work way either:
if(myvid1.currenttime=="5"){ alert("awesome"); };
i see @ to the lowest degree 2 problems code:
you seem executing if statement once, if media doesn't happen @ time want during 1 check, naturally status false. want respond 1 of events on video's associated mediacontroller, timeupdate.
you're looking value of exactly 5. odds not high you'd happen grab exactly value 5. remember currenttime floating-point number. recommend looking myvid1.currenttime > 5 time after 5 seconds, or myvid1.currenttime >= 5 && myvid1.currenttime < 6 if want time within 5th second.
so like:
myvid1=document.getelementbyid("video1"); var trigger = 5; myvid1.controller.addeventlistener('timeupdate', function() { if (myvid1.currenttime >= trigger) { // something, note happen 1 time again , 1 time again unless // set flag or remove handler } }); javascript video
No comments:
Post a Comment