How do you mute an embedded Youtube player?

后端 未结 4 646
闹比i
闹比i 2020-11-28 12:13

I\'m experimenting with the Youtube player but I can\'t get it to mute by default.

function onPlayerReady() {
    player.playVideo();
    // Mute?!
    playe         


        
4条回答
  •  粉色の甜心
    2020-11-28 12:40

    All above answers didn't work for me for some reason. It might be weird wordpress theme that I had to use or depreciated methods at Youtube API, I'm not sure. The only way of muting the player was to insert the code below into tag.

    // Loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');
      tag.src = "https://www.youtube.com/player_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    
      // Replaces the 'ytplayer' element with an