YouTube播放列表代码示例? [英] Example YouTube Playlist Code?
问题描述
我想创建一个播放列表来加载特定用户上传的所有视频。
I'd like to create a playlist that loads all the videos a specific user has uploaded.
我被建议使用以下代码(假设帐户为拉进来是YouTube):
I was suggested to use the following code (assuming the account to pull in is YouTube):
loadPlaylist( { listType: 'user_uploads', list: 'youtube' } );
我也查看了API页面: http://code.google.com/apis/youtube/js_api_reference.html
I have looked over the API pages as well: http://code.google.com/apis/youtube/js_api_reference.html
但我找不到使用加载播放列表的实际示例代码。作为YouTube API的新手,我不知道我需要什么类型的包装器代码才能完成上述工作。这样的事情(当然我缺少部分):
But I can't find an actual example code that uses load playlist. Being completely new to YouTube API I have no idea what type of wrapper code I need to make the above work. Something like this (of course I'm missing parts):
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">
loadPlaylist( { listType: 'user_uploads', list: 'youtube' } );
</script>
或者,如果有人可以提供原始的加载播放列表的工作示例,那将是很棒的,我可以工作关于我自己需要的其他细节。
Or if someone could provide working example with the original loadplaylist line that would be great, and I can work on the other details I need on my own from there.
-YouTube API新手
-YouTube API Newbie
推荐答案
首先,我建议你使用IFRAME嵌入式,因为它适用于桌面和移动(iOS,Android,BB,Windows,非常好)。示例代码位于 Youtube IFRAME嵌入。这个包含你开始的HTML代码。
First of all , I suggest you to use IFRAME embed style, because it work on both desktop and mobile (iOS,Android,BB,Windows, very nice). The sample code is at Youtube IFRAME embed . This one contain the html code for you to get started.
让我们进入你的问题。
1让假设你得到youtube播放器
1 Let assume you get youtube player as
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'u1zgFlCw8Aw',
events: {
'onReady': onPlayerReady
}
});
不关心 videoId 。只需插入任何有效的YouTube视频ID。
don't care with videoId. just insert any valid youtube video's ID.
请注意我们注册'onReady':onPlayerReady
2使用 onPlayerReady将播放列表加载到播放器
function onPlayerReady(event) {
event.target.loadPlaylist({list: "UUPW9TMt0le6orPKdDwLR93w", index: 1, startSeconds: 10,suggestedQuality: "small"});
}
您可以在 Youtube JSAPI参考
希望这项工作对您有用。 ^^。
You can read more on Youtube JSAPI reference Hope this work on you. ^^.
更新
您还可以指定playerVars对象中的播放列表。
you can also specify the playlist in playerVars object.
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'u1zgFlCw8Aw',
playerVars: {
listType:'playlist',
list: 'UUPW9TMt0le6orPKdDwLR93w'
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
这篇关于YouTube播放列表代码示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!