Programmatically force UIWebView to go full screen

When playing a media file in UIWebview (e.g. YouTube)

There is a button "fullscreen" html5 media player. How can I

  • Know when the player has switched to full screen mode
  • Make the HTML5 player go full screen.

enter image description here

+8
ios youtube-api nsnotificationcenter uiwebview youtube-javascript-api
source share
2 answers

And here's how to get webview to exit full-screen video playback:

 [_webView reload]; 

It is not clean, and it will also stop playing the video. But I think this is the only way to get out of full-screen video playback.

+1
source share

To make the video always play in full screen mode, use the following line of code when setting up UIWebView :

 webView.allowsInlineMediaPlayback = NO; 

It seems that there are several ways to detect input and output from full screen mode , although it seems that this is not recommended. See the related StackOverflow question.

Depending on what you are trying to do, it seems that you are better off detecting a player’s state change using the onStateChange . In the project I'm working on, the code is as follows:

  function onStateChange(event) { window.location.href = 'ytplayer://onStateChange?data=' + event.data; } 

Then I sniff this URL in a controller wrapper class or view:

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if([request.URL.scheme isEqualToString:@"ytplayer"]) { NSString *action = request.URL.host; 
0
source share

All Articles