2016-05-18 6 views
1

iOS 9 for iphoneで埋め込みのYouTube動画を再生するためにUIWebViewを使用しています。UIWebViewでYouTube動画を再生するにはどうすればいいですか?

しかし、既知の問題に、ボリュームコントロールが(player.muteを呼び出すすなわち、機能していない)またはplayer.setVolume(0)すべてでは動作しません: https://github.com/youtube/youtube-ios-player-helper/issues/20

私は誰かがこの問題をうまく解決したのかしら?あなたの方法を分かち合うことができますか?私が使用しています

サンプル埋め込まれたHTML:

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

ありがとう!

+0

回避策は、WebViewのプライベート通知を聴き、通知オブジェクトからプレーヤーオブジェクトを取得してからミュートすることです。 –

+0

@MuhammadZeeshanあなたには例がありますか? – RainCast

答えて

3

まず、javacript check this docVolume Control in JavaScriptセクションを読んでボリュームを設定することはできません。 Found here

は、第二に、私はこれを試してみました:

[[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]; 
} 

これは、シミュレータで正常に動作しているようです。しかし、このメソッドはいくつかのプライベートプロパティを使用しています。あなた自身の責任で使用する;)、オブザーバーを削除することを忘れないでください。

+0

それは、感謝ムハンマド、動作します。これが正当なアプローチであるかどうかは分かりますか?私はこれが "ハッキー"だと言っている他の投稿を見てきました。 http://stackoverflow.com/questions/26154823/how-to-get-the-url-of-currently-playing-video-in-uiwebview – RainCast

+0

これはwebviewの内部通知が原因でハッキーです。最近、私はこの通知を聞いているアプリを開発し、アプリストアレビューチームはそれを承認しました。 –

+0

あなたの説明に感謝しました。 – RainCast

関連する問題