UIWebView and MPMoviePlayerController

248 Views Asked by At

I hvae addd one webview having youtube link. When user play viedo it defaults open iOS movie player. I want to track notification of that movie player when it exits full screen or playing stopped. I have tried all notification generated by MPMoviewPlayerController . None of them are being fired. It fiers only when we instatinate MPMoviewPlayerViewCotntroller object and present MPMoviewPlayer from that.

1

There are 1 best solutions below

0
Boaz On BEST ANSWER

That's becuase Youtube videos inside UIWebView are not MPMoviewPlayerViewCotntroller.

On iOS7:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreen:)
                                             name:@"UIMoviePlayerControllerDidEnterFullscreenNotification"
                                           object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerWillExitFullscreen:)
                                             name:@"UIMoviePlayerControllerWillExitFullscreenNotification"  object:nil];

On iOS8 it's a bit of a problem because these events are gone, and you need to add observer like so:

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

And check that when it fires it is indeed a movie player (because it fires also on UIAlertView and stuff):

- (void)ios8EnterFullscreen:(NSNotification *)notification
{
    if ([notification.object isMemberOfClass:[UIWindow class]])
    {
         //do your thing...
    }
}