YouTube API Not Muting in Safari (not iOS)

最后都变了- 提交于 2019-12-25 06:46:01

问题


I have initialized my player with the code below. It mutes fine in Chrome, FireFox, and IE, but not Safari. Any thoughts amigos?

function onYouTubeIframeAPIReady() {
    player = new YT.Player('iframe-wrapper', {
        height: videoHeight,
        width: videoWidth,
        videoId: id,
        events: {
            'onReady': onPlayerReady
        },
        playerVars: {
            'autoplay': 1,
            'controls': 0,
            'autohide': 1,
            'wmode': 'opaque',
            'showinfo': 0,
            'loop': 1,
            'mute': 1
        }
    });
}
  function onPlayerReady() {
    player.mute();
    player.playVideo();
}

回答1:


Just add some code in your onPlayerReady():

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

or you can create a separate function for mute:

function onMute() {
player.mute();
}

function onUnMute() {
player.unMute();
}

Follow the guide code in youtube api document and jsfiddle sample.




回答2:


The problem ended up being that the onPlayerReady event wasn't firing. Apparently this is somewhat of a known issue and isn't terribly well documented in the YouTube API. Here's a link to the answer.



来源:https://stackoverflow.com/questions/36485939/youtube-api-not-muting-in-safari-not-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!