0
隨機播放視頻我的YouTube API,我從這個鏈接了......的YouTube API從標籤
https://developers.google.com/youtube/iframe_api_reference
它的工作好,但我在尋找一種方式,它起到一個隨機基於標籤的視頻......這可能嗎?有關於它的教程嗎?
這裏是我的代碼
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'u1zgFlCw8Aw',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
我不是在此引用,表示看到任何東西你可以通過YouTube標籤搜索視頻(或視頻列表)...你可能會[看這個問題](http://stackoverflow.com/questions/5873185/youtube-api-how-to-get -vide os-from-channel-x-with-tag-y)用於該類別的潛在客戶。 – Nightfirecat 2013-04-05 00:19:28
我試着添加這個代碼:https://gdata.youtube.com/feeds/api/videos?category = bass%2Cfishing&v = 2',它什麼都沒做: – user2247178 2013-04-05 00:34:30
您正在尋找解析註釋中的URL並檢索一個隨機視頻條目,獲取ID並在onYouTubeIframeAPIReady函數的'videoID'參數中使用...不是嗎? – 2013-04-05 23:41:14