获取嵌入式YouTube视频进行自动播放和循环



我正在尝试在页面上嵌入自动播放和自动循环的基本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>

youtubes html5嵌入式代码:

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

您可以在此处阅读有关它的信息:链接在Internet存档项目上的原始内容。

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

相关信息:

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

loop (支持玩家:AS3,HTML5)值:0或1。 单个视频播放器的情况,设置1将导致 玩家一次又一次地播放初始视频。如果是 播放列表播放器(或自定义播放器),玩家将播放整个 播放列表,然后在第一个视频中重新开始。

注意:此参数对AS3播放器和IN的支持有限 iFrame嵌入,可以加载AS3或HTML5播放器。 当前,循环参数在使用时仅在AS3播放器中起作用 与播放列表参数结合使用。为了循环一个视频, 将循环参数值设置为1并设置播放列表参数值 到播放器API URL中已经指定的同一视频ID:

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

在嵌入代码中使用上面的URL(也附加其他参数)。

所有答案对我不起作用,我检查了播放列表URL,并看到播放列表参数更改为list!,所以应该是:

&amp; loop = 1&amp; list = plvnxgp1v1v1dowpdbl7l3ajilkkydndkues

所以这是我使用的完整代码,使整洁,循环,自动播放视频:

<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>

播放列表hack也对我不起作用。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>

有相同的经验,但是对我来说,魔术不是将嵌入到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>

希望它有帮助...

最新更新