Getting Current YouTube Video Time

ytplayer = document.getElementById("movie_player");
ytplayer.getCurrentTime();

See the api

Update: if it didn't work, also try player.playerInfo.currentTime (codepen live example)


You can use Html5 Video API on youtube.com

var htmlVideoPlayer = document.getElementsByTagName('video')[0];
htmlVideoPlayer.currentTime

Note: It's not gonna work on Youtube Iframe API because Iframes are isolated. You cannot access the context of a Youtube IFrame .


Depends on what you want

player.getCurrentTime():Number

Returns the elapsed time in seconds since the video started playing.

player.getDuration():Number

Returns the duration in seconds of the currently playing video. Note that getDuration() will return 0 until the video's metadata is loaded, which normally happens just after the video starts playing.

http://code.google.com/apis/youtube/js_api_reference.html


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:

  • YouTube IFrame API
  • YouTube JavaScript API
  • YouTube Player Demo