Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Current YouTube Video Time

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 JavaScript Console and haven't had any luck.

It appears that the chrome API only works with embedded video players not a video that is playing on on youtube.com. One option I looked into is in the share section of a video their is an input box for the "start at:" time that contains the current time of the video. I have tried using .value and .text on this input box and they both return undefined? Does anyone have any ideas?

like image 882
James Avatar asked Aug 07 '11 00:08

James


People also ask

How do I put a timestamp on YouTube on mobile?

You can also create a timestamp link with the YouTube android app, First, open the video and drag the playtime cursor to the desired duration to create the timestamp. ' Next, open the “share” button to open the pop-up box.


1 Answers

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

See the api

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

like image 71
Joseph Marikle Avatar answered Sep 21 '22 09:09

Joseph Marikle