Вопрос

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

Это было полезно?

Решение

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;

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top