1

I am looking for a way to mute the video unless the user unmutes it.

<iframe id="video" src="https://www.youtube.com/embed/ShPQqM50Vz0?autoplay=1&showinfo=0&controls=0" frameborder="0" allowfullscreen></iframe>

I tried using this script but nothing shows up at all

 <div id="player"></div>
<script>
      var tag = document.createElement('script');
      tag.src = "http://www.youtube.com/player_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      var player;
      function onYouTubePlayerAPIReady() {
        player = new YT.Player('player', {
          playerVars: { 'autoplay': 1, 'controls': 1,'autohide':1,'wmode':'opaque' },
          videoId: 'ShPQqM50Vz0',
          events: {
            'onReady': onPlayerReady}
        });
      }

      function onPlayerReady(event) {
        event.target.mute();
      }
</script>
nha
  • 17,623
  • 13
  • 87
  • 133
BragDeal
  • 748
  • 2
  • 10
  • 25
  • possible duplicate of [How do I automatically play a Youtube video (IFrame API) muted?](http://stackoverflow.com/questions/8869372/how-do-i-automatically-play-a-youtube-video-iframe-api-muted) – Kirill Fedyanin Aug 23 '15 at 20:27
  • It isn't really as I clearly copied the code from there but it's not working for me – BragDeal Aug 23 '15 at 22:19

1 Answers1

1

Load API over https:

tag.src = "https://www.youtube.com/player_api";

https://jsfiddle.net/frzwg0bm/

172d042d
  • 653
  • 8
  • 19