0
votes

I’m attempting to use a YouTube video as a background but am unable to set the following parameters using The YouTube video API

    'autoplay': 1, 'controls': 0, 'mute' : 1, 'loop': 1

I’ve set my example on CodePen.

https://codepen.io/randometc/pen/GBXvKP

The function onYouTubeIframeAPIReady()

seems to be working(?) because the onStateChange function is firing.

    function onYouTubeIframeAPIReady() {
          player = new YT.Player('existing-iframe-example', {
          videoId: 'cLzY3cmrgIU',
          playerVars: {'autoplay': 1, 'controls': 0, 'mute' : 1, 'loop': 1 },
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
            }
          });
        }

But the PlayerVars are not being read at all.

1

1 Answers

0
votes

You may want to add the attributes to the end of that embed link as stated in this link. Example:

<iframe width="853" height="480" src="//www.youtube.com/v/lG5aSZBAuPs&autoplay=1&loop=1&playlist=lG5aSZBAuPs" frameborder="0" allowfullscreen></iframe>

Also based from this documentation regarding loop:

This parameter has limited support in the AS3 player and in IFrame embeds, which could load either the AS3 or HTML5 player. 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.