Implement with iframe vide from Youtube silently (muted)

0

I have integrated a video gallery in wordpress with I have seen that there are many options to configure these videos but not the option to silence them

    <iframe id="video" src="<?php echo $result; ?>?rel=0&vq=hd720&autoplay=1&loop=1&playlist=<?php echo $playlist[1]; ?>" frameborder="0" allowfullscreen></iframe>

The php code is because it is not always the same video but as I said vá varying depending on the bloy and the gallery.

I've seen tutorials with many options but it's not what I need ( link ).

    
asked by TamZam 12.07.2017 в 11:14
source

1 answer

0

Finally the solution:

HTML and PHP

<iframe id="video<?php echo $playlist[1]; ?>" class="video" src="<?php echo $result; ?>?rel=0?vq=hd1080&amp;autoplay=1&amp;hd=1&amp;playlist=<?php echo $playlist[1]; ?>;enablejsapi=1" frameborder="0" allowfullscreen></iframe>

JAVASCRIPT

var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

var players;
function onYouTubePlayerAPIReady() {
    var players = document.querySelectorAll('.video')
    for (var i = 0; i < players.length; i++) {
        new YT.Player(players[i], {
                    events: {
                        'onReady': onPlayerReady
                    },
          videoId: players[i].dataset.id
        });
    }

}

function onPlayerReady(event) {
  event.target.mute();
}

Thank you!

    
answered by 12.07.2017 в 14:21