Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube iframe "loop" doesn't work

I tried to use the YouTube player demo to generate the code necessary for my video to autoplay and loop itself. But only the autoplay works, it doesn't loop, and the demo-video doesn't work either. Here is the code I've used.

<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>
like image 760
Seal Blue Avatar asked Sep 11 '14 05:09

Seal Blue


People also ask

Why is loop not working on YouTube?

Step 2: Move your cursor over the More tools option and then choose the Extensions option. Step 3: On the Extensions page, see if there is an extension related to Adblocker. If yes, toggle the bar to the left side to disable it. Then, switch to the YouTube tab and reuse the Loop feature to see if it will work well.

How do I get an embedded YouTube video to loop?

First of all, open a video on youtube then click on the share button, then click the embed button. After clicking on the embed button a popup will be open. Then copy the iframe and place it in your HTML.


Video Answer


4 Answers

Try adding the playlist parameter along with the loop. For playlist, set it's value as the current video 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>

Currently, the loop parameter only works in the AS3 player when used in conjunction with the playlist parameter. To loop a single video, set the loop parameter value to 1 and set the playlist parameter value to the same video ID already specified in the Player API URL:

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

Reference:https://developers.google.com/youtube/player_parameters#loop

like image 193
K K Avatar answered Oct 27 '22 07:10

K K


Using in react native like this, make sure to use same video ID value for playlist as well.

for e.g if video id is SpongeBOB then url will be like this :

https://www.youtube.com/embed/SpongeBOB?playlist=SpongeBOB&loop=1

below is implementation in react native webview

<WebView
  javaScriptEnabled={true}
  domStorageEnabled={true}
  mediaPlaybackRequiresUserAction={true}
  style={{ height:180, width:300,alignSelf:"center",alignContent:"center"}}
  source={{uri: 'https://www.youtube.com/embed/qD101Xlc5uw?playlist=qD101Xlc5uw&loop=1' }}
 />
like image 22
Abhishek Garg Avatar answered Oct 27 '22 05:10

Abhishek Garg


I just figured out you need to have playlist="" to use loop.

<iframe src="https://www.youtube.com/embed/peSfCy7HFrM?playlist=peSfCy7HFrM&loop=1;rel=0&autoplay=1&controls=0&showinfo=0" frameborder="0" allowfullscreen>
like image 13
Lana Đỗ Avatar answered Oct 27 '22 07:10

Lana Đỗ


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

inside playerVars.

For example a full code:

<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');
      }

Your Html code:

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

If you want to keep video in a variable use this:

<?php $youtube_video='C0DPdy98e4c';?>
like image 5
Zakir Sajib Avatar answered Oct 27 '22 06:10

Zakir Sajib