I am writing a Browser Plugin and need to find a way to get the current time a YouTube Video playing on YouTube using JavaScript. I have been playing around in the Chrome Ja
Finally I found how to make it work on iOS (and Android too).
Actually, the whole youtube js api was broken for me if run on mobile browser.
Problem solved by creating player using new YT.Player
as described in YouTube IFrame API.
Please note: only creating <iframe>
from <div>
placeholder works for mobile browsers at the time. If you try to use existing <iframe>
in new YT.Player
call, as mentioned in IFrame API, this will not work.
After player created, it's possible to use player.getCurrentTime()
or player.getDuration()
with player
instance created.
Note: I had no luck calling this methods on player obtained with
player = document.getElementById(...)
(from @JosephMarikle answer).
Only created player
instance worked in mobile browsers.
Useful links: