copyflake
copyflake

Reputation: 7107

Retrieving TITLE of current video with YouTube JS API

I have created a YouTube player with the YouTube Javascript API that loads up a playlist I have created.

Because the video is chromeless, it does not display controls or video info. I was hoping to pull the title of the currently playing video and display it underneath. I can pull information such as current time position, and current video duration with things like ytplayer.getDuration() and ytplayer.getCurrentTime().

Wondering if something like "ytplayer.getTitle()" might exist but be undocumented?

Upvotes: 2

Views: 2730

Answers (3)

Ephenodrom
Ephenodrom

Reputation: 1893

If you use the getVideoData method, you will get access to the title. See the codesnipped, i tried this and it printed the line below to the console.

console.log(player.getVideoData().title);
Necrotic Flesh - Prenatal Decomposed

Upvotes: 1

user3014013
user3014013

Reputation: 51

It is possible, for everyone that are still looking for answer of this question there is a javascript function:

player.getVideoData().title

Upvotes: 5

jlmcdonald
jlmcdonald

Reputation: 13667

You can't get the title from the ytplayer object, as that's really just an interface to the player controls. But you could add in a quick call to the video feed (perhaps as a part of the onPlayerReady function, but it could really be anywhere). For example, with jQuery this would only require:

$.get('http://gdata.youtube.com/feeds/api/videos/[videoid]?v=2&alt=json',function(data) {
       title=data.entry.title.$t;
});

Upvotes: 2

Related Questions