ios - 如何在 UIWebView 中播放 youtube 视频静音?
<p><p>我正在使用 UIWebView 在 iOS 9 for iphone 上播放嵌入的 youtube 视频。</p>
<p>但是,由于<strong>一个已知问题</strong>,音量控制不起作用,即调用 player.mute() 或 player.setVolume(0) 根本不起作用:
<a href="https://github.com/youtube/youtube-ios-player-helper/issues/20" rel="noreferrer noopener nofollow">https://github.com/youtube/youtube-ios-player-helper/issues/20</a> </p>
<p>我想知道是否有人成功解决了这个问题?能否分享一下你的方法。</p>
<p>我正在使用的示例嵌入式 html:</p>
<pre><code> <html><body style='margin:0px;padding:0px;'>
<script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>
var player;
function onYouTubeIframeAPIReady()
{player=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}
function onPlayerReady(event){player.mute();player.setVolume(0);player.playVideo();}
</script>
<iframe id='playerId' type='text/html' width='1280' height='720'
src='https://www.youtube.com/embed/R52bof3tvZs?enablejsapi=1&rel=0&playsinline=1&autoplay=1&showinfo=0&autohide=1&controls=0&modestbranding=1' frameborder='0'>
</body></html>
</code></pre>
<p>谢谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>首先你不能使用javascript检查设置音量<a href="https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW10" rel="noreferrer noopener nofollow">this doc</a>并阅读 <code>JavaScript 中的音量控制</code> 部分。 <a href="https://stackoverflow.com/questions/29239491/how-can-i-volume-set-in-uiwebview-with-swift" rel="noreferrer noopener nofollow">Found here</a> .</p>
<p>第二次我尝试了这个:</p>
<pre><code>[ addObserver:self
selector:@selector(playerItemBecameCurrentNotif:)
name:@"AVPlayerItemBecameCurrentNotification"
object:nil];
- (void)playerItemBecameCurrentNotif:(NSNotification*)notification {
AVPlayerItem *playerItem = notif.object;
AVPlayer *player = ;
;
}
</code></pre>
<p>这似乎在模拟器中运行良好。但是,此方法使用了一些私有(private)属性。使用风险自负;)并且不要忘记删除观察者。</p></p>
<p style="font-size: 20px;">关于ios - 如何在 UIWebView 中播放 youtube 视频静音?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37290108/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37290108/
</a>
</p>
页:
[1]