使用YouTube API显示用户上传的视频



我想创建一个网站,允许用户将视频上传到YouTube频道,并将这些YouTube视频嵌入我的网站。这可能使用YouTube的API吗?我该如何着手学习如何做到这一点?我熟悉HTML5/CSS3和Python,熟悉Java和JavaScript。非常感谢您的任何建议。

你试过了吗?YouTube API

YouTube API有python API,允许您在网站上使用YouTube

下面是使用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&#39;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>&nbsp;&nbsp;&nbsp;
<a href="javascript:playVideo('q3p1eexyUxY');">Part 2 (29:25)</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:playVideo('R17mYVS4ZMg');">Part 3 (29:17)</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:playVideo('jDiaFwVfHWg');">Part 4 (01:53)</a>&nbsp;&nbsp;&nbsp;
<a href="javascript:queueVideo(4,['naz9POIJvwI','q3p1eexyUxY','R17mYVS4ZMg','jDiaFwVfHWg']);">All</a>&nbsp;&nbsp;&nbsp;
</p>
</body>
</html>

我希望这能有所帮助!

相关内容

  • 没有找到相关文章

最新更新