HTML5 video supports the ontimeupdate
event; is there an equivalent in the YouTube API that either isn't listed in the docs, or just that I'm unaware of? I've tried a setInterval method to check every n milliseconds, but then I have to check to see if the video is playing, etc. Has anyone dealt with this issue?
According to the documentation there is no such an event (I think you are also aware of this). Other answers also state this and as far as I have seen over code examples, there is no direct equivalent. Even in some of the code examples (check the getting started code), they rely on setTimeout in order to do something 6 seconds after the video has started.
Some people have find work arounds, for example in this answer, they create a timer so they can actually fire every X milliseconds a time check:
function onPlayerReady() {
function updateTime() {
var oldTime = videotime;
if(player && player.getCurrentTime) {
videotime = player.getCurrentTime();
}
if(videotime !== oldTime) {
onProgress(videotime);
}
}
timeupdater = setInterval(updateTime, 100);
}
In this way you could actually simulate the event timeupdate, you just need also to clear the timeout on state change (if it is stopped you do not want to continuously call the function).
Some people have create a YouTube Player API wrapper like HTML5 video API. In that one you are actually accessing the HTML5 video API in the embedded Youtube Video.
I am not sure of the roadmap of the Youtube API, but probably they will move to a more generic and standard api that is compatible with the current HTML5 Video one, but until then I hope my answer can help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With