获得嵌入式YouTube视频自动播放和循环(Getting an Embedded YouTube

2019-07-02 11:04发布

我想获得一个基本的Youtube视频自动播放和嵌入在页面上自动循环,但我有没有运气。

<div style="text-align: center; margin: auto"><object type="application/x-shockwave-flash" style="width:1120px; height:630px;" data="http://www.youtube.com/v/GRonxog5mbw?rel=0&amp;loop=1&amp;autoplay=1&amp;showsearch=0&amp;version=3&amp;showinfo=0&amp;modestbranding=1&amp;fs=1">
<param name="movie" value="http://www.youtube.com/v/GRonxog5mbw?rel=0&amp;loop=1&amp;autoplay=1&amp;showsearch=0&amp;version=3&amp;showinfo=0&amp;modestbranding=1&amp;fs=1" />
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
</object></div>

Answer 1:

YouTubes HTML5嵌入代码:

<iframe width="560" height="315" src="http://www.youtube.com/embed/GRonxog5mbw?autoplay=1&loop=1&playlist=GRonxog5mbw" frameborder="0" allowfullscreen></iframe>​

你可以在这里读到它:......( 编辑链接死了。)...查看互联网档案馆项目的原创内容。

http://web.archive.org/web/20121016180134/http://brianwong.com/blog/2012-youtube-embed-code-autoplay-on-and-all-other-parameters/



Answer 2:

下面是完整列表YouTube嵌入式播放器的参数 。

相关信息:

自动播放 (支持播放器:AS3,AS2,HTML5)值:0或1默认值为0设置初始视频是否会在播放器加载自动播放。

(支持的播放器:AS3,HTML5)值:0或1。默认为0。在一个单一的视频播放器的情况下,1的设置将导致玩家反复播放初始视频。 在播放列表播放器(或自定义播放器)的情况下,玩家将扮演整个播放列表,然后在第一视频再次启动。

注意:此参数在AS3玩家有限的支持,并在iframe嵌入,它可以加载无论是AS3或HTML5播放器。 目前,在播放列表参数一起使用时,回路参数只能在AS3播放器。 要循环中的单个视频回路参数值设置为1,并设置播放列表参数值在播放器API URL已经指定了相同的视频ID:

http://www.youtube.com/v/VIDEO_ID?version=3&loop=1&playlist=VIDEO_ID

使用以上网址中您的嵌入代码(附加其他参数也是如此)。



Answer 3:

所有的答案并没有为我工作,我查了播放列表的网址,看到改为列出播放列表参数! 因此,它应该是:

&循环= 1&列表= PLvNxGp1V1dOwpDBl7L3AJIlkKYdNDKUEs

因此,这里是完整的代码我用做清洁,循环,自动播放视频:

<iframe width="100%" height="425" src="https://www.youtube.com/embed/MavEpJETfgI?autoplay=1&showinfo=0&loop=1&list=PLvNxGp1V1dOwpDBl7L3AJIlkKYdNDKUEs&rel=0" frameborder="0" allowfullscreen></iframe>


Answer 4:

有相同的经历,但是没有什么神奇的,我是不改变嵌入到v。

因此,代码会看起来像这样...

<iframe width="560" height="315" src="https://www.youtube.com/embed/cTYuscQu-Og?Version=3&loop=1&playlist=cTYuscQu-Og" frameborder="0" allowfullscreen></iframe>

希望能帮助到你...



Answer 5:

播放列表黑客并没有为我工作的。 工作解决方法2018年9月(奖金:通过设置CSS宽度和高度#yt-wrap ,而不是硬编码在JS):

<div id="yt-wrap">
    <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
    <div id="ytplayer"></div>
</div>

<script>
  // 2. This code loads the IFrame Player API code asynchronously.
  var tag = document.createElement('script');
  tag.src = "https://www.youtube.com/player_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 onYouTubePlayerAPIReady() {
    player = new YT.Player('ytplayer', {
      width: '100%',
      height: '100%',
      videoId: 'VIDEO_ID',
      events: {
        'onReady': onPlayerReady,
        'onStateChange': onPlayerStateChange
      }
    });
  }

  // 4. The API will call this function when the video player is ready.
  function onPlayerReady(event) {
    event.target.playVideo();
    player.mute(); // comment out if you don't want the auto played video muted
  }

  // 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.
  function onPlayerStateChange(event) {
    if (event.data == YT.PlayerState.ENDED) {
      player.seekTo(0);
      player.playVideo();
    }
  }
  function stopVideo() {
    player.stopVideo();
  }
</script>


文章来源: Getting an Embedded YouTube Video to Auto Play and Loop