我想创建一个网站,允许用户将视频上传到YouTube频道,并将这些YouTube视频嵌入我的网站。这可能是使用YouTube的API吗?我将如何学习如何做到这一点?我熟悉HTML5 / CSS3和Python,熟悉Java和JavaScript。任何建议都非常感谢。
答案 0 :(得分:0)
YouTube API具有python API,可让您在自己的网站上使用YouTube
答案 1 :(得分:0)
以下是使用JavaScript调用YouTube播放器以播放网页中嵌入的视频的示例页面。该示例显示了如何只播放一个视频以及如何排列多个视频然后播放它们。加载页面时,示例会自动播放默认视频。视频播放完毕后,将播放默认视频。
<!doctype html>
<html lang="en">
<head>
<title>Play YouTube Videos</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
var videosQueuedCount;
function onYouTubePlayerAPIReady() {
videosQueuedCount = 1;
var vars = {
autoplay: 1,
enablejsapi: 1,
controls: 1
}
player = new YT.Player('ytplayer', {
height: '390',
width: '640',
playerVars: vars,
videoId:'HL6ZL9q3UJ8',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(evt) {
}
function playVideo(VID) {
window.top.scrollTo(0,200);
videosQueuedCount = 1;
player.loadVideoById(VID);
}
function queueVideo(queuedCount,VID) {
window.top.scrollTo(0,200);
videosQueuedCount = queuedCount;
player.loadPlaylist(VID);
player.playVideo();
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
videosQueuedCount -= 1;
if (videosQueuedCount < 1) {
videosQueuedCount = 1;
playVideo('HL6ZL9q3UJ8');
}
}
}
</script>
<div id="ytplayer"></div>
<p><b>10/22/2015</b> <a href="javascript:playVideo('kaLlstcp5GE');">East Lyme, CT Issues and Answers (28:26)</a><br>
Information<br>Teri Smith of Smith's Acres and Niantic Main Street<br>
</p>
<p><b>10/21/2015 East Lyme, CT Board of Selectmen Meeting</b><br>
Regular Meeting<br>
<a href="javascript:playVideo('naz9POIJvwI');">Part 1 (28:50)</a>
<a href="javascript:playVideo('q3p1eexyUxY');">Part 2 (29:25)</a>
<a href="javascript:playVideo('R17mYVS4ZMg');">Part 3 (29:17)</a>
<a href="javascript:playVideo('jDiaFwVfHWg');">Part 4 (01:53)</a>
<a href="javascript:queueVideo(4,['naz9POIJvwI','q3p1eexyUxY','R17mYVS4ZMg','jDiaFwVfHWg']);">All</a>
</p>
</body>
</html>
我希望这有帮助!