How do you mute an embedded Youtube player?

后端 未结 4 653
闹比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:49

    Turns out player.mute() works fine. It only needed the parameter enablejsapi=1. Initial test in the fiddle didn't work because the player initiation had an error. The following works.

    HTML:

    
    

    JS:

    var player;
    
    function onYouTubeIframeAPIReady() {
        player = new YT.Player('ytplayer', {
            events: {
                'onReady': onPlayerReady
            }
        });
    }
    
    function onPlayerReady(event) {
        player.mute();
        player.playVideo();
    }
    

    Fiddle

    Credit to Gagandeep Singh and Anton King for pointing to enablejsapi=1

提交回复
热议问题