问题
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