如何在UIWebView中播放youtubevideo静音?

我在iOS 9 for iphone上使用UIWebView播放嵌入式YouTubevideo。

但是,由于已知问题 ,音量控制无效,即调用player.mute()或者player.setVolume(0)根本不起作用: https : //github.com/youtube/youtube-ios-玩家帮手/问题/ 20

我想知道是否有人成功地解决了这个问题? 你能分享一下你的方法吗?

我正在使用的示例嵌入式html:

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

谢谢!

首先,您无法使用javascript设置音量检查此文档并阅读Volume Control in JavaScript部分中的Volume Control in JavaScript 。 在这里找到 。

其次我试过这个:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemBecameCurrentNotif:) name:@"AVPlayerItemBecameCurrentNotification" object:nil]; - (void)playerItemBecameCurrentNotif:(NSNotification*)notification { AVPlayerItem *playerItem = notif.object; AVPlayer *player = [playerItem valueForKey:@"player"]; [player setVolume:0.0]; } 

这似乎在模拟器中工作正常。 但是,此方法使用一些私有属性。 使用风险;)并且不要忘记删除观察者。