Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically force a UIWebView to go to full screen mode

When playing a media file in a UIWebview (youtube for instance)

there is a button to "fullscreen" the html5 media player - How can I

  • Know when the player went to full screen
  • Force the HTML5 player to go to full screen

enter image description here

like image 765
Avner Barr Avatar asked Jan 13 '14 21:01

Avner Barr


2 Answers

To force videos to always play in fullscreen, when configuring your UIWebView, use this line of code:

webView.allowsInlineMediaPlayback = NO;

It looks like there are a few ways to detect entering and leaving fullscreen, though it seems like these are not recommended approaches. See the linked StackOverflow question.

Depending on what you're trying to do, it almost seems like you're better off detecting player state change using the onStateChange callback. In a project I'm working on, the code looks like this:

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

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

- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
            navigationType:(UIWebViewNavigationType)navigationType {
if([request.URL.scheme isEqualToString:@"ytplayer"]) {
    NSString *action = request.URL.host;
like image 187
Ikai Lan Avatar answered Oct 16 '22 23:10

Ikai Lan


And here is how to force webview to exit video playback fullscreen:

[_webView reload];

It's not clean and it will also stop video playback. But I think this is the only way to exit video fullscreen playback.

like image 44
Borut Tomazin Avatar answered Oct 17 '22 00:10

Borut Tomazin