我想使用本教程 API从youtube构建一个定制的YouTube播放列表,但是我被困在了某个点上。我基本上嵌入了client.js脚本并在加载时执行它的功能,之后,我还嵌入了教程中提到的YouTubePlayList.js文件。这是我想要做的事情的小提琴。我确实在控制台中接收到了YouTubePlayList对象,但它似乎没有给出任何适当的数据。我需要一个工作脚本的例子或指导如何实现它的工作,并在我的客户端呈现播放列表。感谢提前,任何帮助感谢!
联署材料:
<pre>
function YouTubePlayList (id, entries) {
this.id = id;
this.entries = entries;
this.currently_playing = 0;
this.randomizer = false;
}
var requestOptions = {
playlistId: 'PLLzJfby7cTLTbusOgXca-yIpVOImC1mWe',
part: 'contentDetails, snippet',
execute: function(response) {
var entries = [];
$.each(response.items, function(key, val){
var entry = {};
entry.video_id = val.snippet.resourceId.videoId;
entry.image_src = val.snippet.thumbnails.medium.url;
entry.title = val.snippet.title;
entry.note = val.contentDetails.note;
entries.push(entry);
});
}
};
window['PLLzJfby7cTLTbusOgXca-yIpVOImC1mWe'] = new YouTubePlayList('PLLzJfby7cTLTbusOgXca-yIpVOImC1mWe', 1);
console.log(window['PLLzJfby7cTLTbusOgXca-yIpVOImC1mWe']);
</pre>发布于 2017-08-09 10:39:40
你可以访问播放列表:插入
这将帮助您在您的频道创建一个新的播放列表。这一页充满了帮助你开始的想法。还有一些例子,如下面的.js代码。
// Define some variables used to remember state.
var playlistId, channelId;
// After the API loads, call a function to enable the playlist creation form.
function handleAPILoaded() {
enableForm();
}
// Enable the form for creating a playlist.
function enableForm() {
$('#playlist-button').attr('disabled', false);
}
// Create a private playlist.
function createPlaylist() {
var request = gapi.client.youtube.playlists.insert({
part: 'snippet,status',
resource: {
snippet: {
title: 'Test Playlist',
description: 'A private playlist created with the YouTube API'
},
status: {
privacyStatus: 'private'
}
}
});
request.execute(function(response) {
var result = response.result;
if (result) {
playlistId = result.id;
$('#playlist-id').val(playlistId);
$('#playlist-title').html(result.snippet.title);
$('#playlist-description').html(result.snippet.description);
} else {
$('#status').html('Could not create playlist');
}
});
}
// Add a video ID specified in the form to the playlist.
function addVideoToPlaylist() {
addToPlaylist($('#video-id').val());
}
// Add a video to a playlist. The "startPos" and "endPos" values let you
// start and stop the video at specific times when the video is played as
// part of the playlist. However, these values are not set in this example.
function addToPlaylist(id, startPos, endPos) {
var details = {
videoId: id,
kind: 'youtube#video'
}
if (startPos != undefined) {
details['startAt'] = startPos;
}
if (endPos != undefined) {
details['endAt'] = endPos;
}
var request = gapi.client.youtube.playlistItems.insert({
part: 'snippet',
resource: {
snippet: {
playlistId: playlistId,
resourceId: details
}
}
});
request.execute(function(response) {
$('#status').html('<pre>' + JSON.stringify(response.result) + '</pre>');
});
}IFrame player API允许您在网站上嵌入YouTube视频播放器,并使用JavaScript控制播放机。 使用API的JavaScript函数,您可以排队播放视频;播放、暂停或停止这些视频;调整播放机音量;或检索正在播放的视频的信息。您还可以添加事件侦听器,这些侦听器将响应某些播放器事件,例如播放机状态更改或视频播放质量更改而执行。 本指南解释了如何使用IFrame API。它标识API可以发送的不同类型的事件,并解释如何编写事件侦听器来响应这些事件。它还详细介绍了可以调用以控制视频播放器的不同JavaScript函数以及可用于进一步自定义播放机的播放机参数。
https://stackoverflow.com/questions/45563539
复制相似问题