如何使用 YouTube JavaScript API 播放播放列表 [英] How to Play a Playlist using YouTube JavaScript API

查看:35
本文介绍了如何使用 YouTube JavaScript API 播放播放列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用今年 1 月推出的用于 iframe 嵌入的 JavaScript API 来播放 youtube 播放列表.http://apiblog.youtube.com/2011/01/introducing-javascript-player-api-for.html

I'm trying to play a youtube playlist using this JavaScript API for iframe-embeds introduced this January. http://apiblog.youtube.com/2011/01/introducing-javascript-player-api-for.html

注意下面的 iframe 标签和带有/p"的链接来表示它的播放列表.

Note the iframe tag below and the link which has "/p" to denote its a playlist.

<iframe src="http://www.youtube.com/embed/p/ID" width="100%" height="500" frameborder="0"></iframe>

但是,即使在 http://code.google.com/apis/的文档中youtube/iframe_api_reference.html 我无法找到如何使用 onYouTubePlayerAPIReady() 调用播放播放列表.

However even in the documentation at http://code.google.com/apis/youtube/iframe_api_reference.html I'm not able to find how can I play a playlist using onYouTubePlayerAPIReady() call.

推荐答案

由于此处没有为使用播放列表 ID 的播放列表提供正确答案(即不硬编码视频列表),如果您仍然希望使用 Javascript Youtube IFrame API.如果在 playerVars 中指定了播放列表 ID,则可以省略 videoID,如下所示:

Since a proper answer was not provided here for playlists using the Playlist ID (i.e. not hardcoding the list of videos), this is the way to use it if you still wish to use the Javascript Youtube IFrame API. You can omit the videoID if the playlist ID is specified in the playerVars as follows:

function onYouTubePlayerAPIReady() 
{
        player = new YT.Player('player', 
        {
          height: '390',
          width: '640',
          playerVars: 
          {
            listType:'playlist',
            list: '<YOURPLAYLISTID>'
          }
        });
}

希望它对正在寻找它的人有所帮助(就像我一样).

Hope it helps who's looking for it (as I was).

这篇关于如何使用 YouTube JavaScript API 播放播放列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆