Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView Media Player fullscreen detection

Before iOS 8, the UIMoviePlayerControllerDidEnterFullscreenNotification notification was sent any time a media player went to fullscreen from a UIWebView. In iOS 8, this doesn't happen and some have suggested to listen for the AVPlayerItemBecameCurrentNotification notification instead. This doesn't appear to be sent from WKWebView. Listening for the UIWindowDidBecomeVisibleNotification notification doesn't work because it's fired for all windows that are added (including things like ad networks)

Bottom line, I've been working on this all night and I can't seem to figure out how to determine if a video was opened in full screen with a WKWebView. Any help would be appreciated.

Edit: To confirm, I created a blank project. Added a UIWebView and the AVPlayerItemBecameCurrentNotification listener to it and it got triggered when I played a video and it entered full screen. I switched that UIWebView to a WKWebView and that notification was no longer triggered.

like image 751
Steve E Avatar asked Dec 03 '14 11:12

Steve E


1 Answers

This workaround seems to work on iOS8 & iPhone 6

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    ...

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowBecameHidden:) name:UIWindowDidBecomeHiddenNotification object:nil];

    return TRUE;
}

- (void)windowBecameHidden:(NSNotification *)notification {

    UIWindow *window = notification.object;

    if (window != self.window) {    // Not my own window: assuming the video window was hidden, maybe add some more checks here.

            // Add code here
    }
}
like image 120
tom knoflook Avatar answered Sep 19 '22 09:09

tom knoflook