2014-09-11 82 views
29

我試圖使用YouTube player demo來生成我的視頻自動播放和循環播放自己所需的代碼。 但是隻有自動播放才起作用,它不會循環播放,演示視頻也不起作用。這是我用過的代碼。Youtube iframe「loop」不起作用

<iframe class="embed-responsive-item" id="ytplayer" type="text/html" width="640" height="360" src="https://www.youtube.com/embed/M7lc1UVf-VE?&autoplay=1&loop=1&rel=0&showinfo=0&color=white&iv_load_policy=3" frameborder="0" allowfullscreen> 
</iframe> 

回答

74

嘗試添加playlist參數與循環一起。對於播放列表,請將其值設置爲當前視頻ID。

<iframe class="embed-responsive-item"id="ytplayer" type="text/html" width="640" height="360" src="https://www.youtube.com/embed/M7lc1UVf-VE?&autoplay=1&loop=1&rel=0&showinfo=0&color=white&iv_load_policy=3&playlist=M7lc1UVf-VE" 
     frameborder="0" allowfullscreen></iframe> 

當前,循環參數僅在AS3播放器與播放列表參數結合使用時起作用。要循環的單個視頻,環路參數值設置爲1,並設置播放列表的參數值,以在播放器API的URL已經指定的相同視頻ID:

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

參考:https://developers.google.com/youtube/player_parameters#loop

+1

感謝一百萬次。這工作。注意現在你應該用'&'而不是'&' – tonkihonks13 2018-03-02 01:21:18

0
'playlist': '<?php echo $youtube_video ?>' 

內部playerVars。

例如一個全碼:

<script> 
// 2. This code loads the IFrame Player API code asynchronously. 
     var tag = document.createElement('script'); 

     tag.src = "https://www.youtube.com/iframe_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 onYouTubeIframeAPIReady() { 
     player = new YT.Player('player', { 
      height:'100%', 
      width: '100%', 
      fitToBackground: true, 
      videoId: '<?php echo $youtube_video ?>', 
      playerVars: { 
       'autoplay': 1, 
       'controls': 0, 
       'autohide':1, 
       'enablejsapi':1, 
       'loop':1, 
       'disablekb':1, 
       'fs': 0, 
       'modestbranding': 0, 
       'showinfo': 0, 
       'color': 'white', 
       'theme': 'light', 
       'rel':0 , 
       'playlist': '<?php echo $youtube_video ?>' 
      }, 
      events: { 
      'onReady': onPlayerReady 
      } 
     }); 
     } 

     // 4. The API will call this function when the video player is ready. 
     function onPlayerReady(event) { 
     event.target.playVideo(); 
     player.mute(); 
     player.setVolume(0); 
     //player.setSize(1920, 1080); 
     player.setLoop(true); 
     player.setPlaybackQuality('hd1080'); 
     } 

你的HTML代碼:

<div id="player"></div> 

如果你想保留的視頻在一個變量使用這樣的:

<?php $youtube_video='C0DPdy98e4c';?> 
+0

絕對是我在找的東西!它運作良好,謝謝! – 2016-07-07 14:23:08

0

我只知道:你是d爲具有播放列表= 「」,以使用循環

SRC =「https://www.youtube.com/embed/peSfCy7HFrM?playlist=peSfCy7HFrM &循環= 1;相對= 0 &自動播放= 1個&對照= 0 & showinfo = 0「frameborder =」0「allowfullscreen>