get youtube playlist index
I have a playlist embeded in my website using the youtube API (with javascript ) and the playlist has 3 songs.
QUESTION: How can I get the index of the song that is currently playing?
ELABORATING ON WHAT I MEAN:
In the following snippet of code:
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
loadPlaylist:{
listType:'playlist',
list:['1asdfasdfs','2asdfasdfs','3asdfasdfs'],
index:parseInt(0),
suggestedQuality:'small'
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
index:parseInt(0)
is telling the youtube api to start playing the song from the first song in the list ( 1asdfasdfs
). I am assuming that this index is contantly shifting, since the users can click any of the 3 songs in the playlist and shift to another song at any time they want. What I would like is to know what method exists to get the current index.
Note: I recognize that I could be a bit hacky and use player.getVideoData()['video_id'];
to retrieve the video id, and then loop through the list of three songs ['1asdfasdfs','2asdfasdfs','3asdfasdfs']
and then save the position of that video id in the array, however I believe there is a cleaner method available, possibly a method in the youtube api? I can't seem to find it anywhere though.
You probably want to just use player.getPlaylistIndex()
https://developers.google.com/youtube/iframe_api_reference#Retrieving_video_information
链接地址: http://www.djcxy.com/p/28958.html上一篇: Youtube playlistItems列表API有时有效,有时会抛出404
下一篇: 获取YouTube播放列表索引