0

我添加了一个具有 youtube 链接的 webview。当用户播放视频时,它默认打开 iOS 电影播放器​​。我想在该电影播放器​​退出全屏或播放停止时跟踪它的通知。我已经尝试了 MPMoviewPlayerController 生成的所有通知。他们都没有被解雇。只有当我们启用 MPMoviewPlayerViewCotntroller 对象并从中呈现 MPMoviewPlayer 时,它才会触发。

4

1 回答 1

3

那是因为里面的 Youtube 视频UIWebView不是MPMoviewPlayerViewCotntroller

在 iOS7 上:

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

在 iOS8 上这有点问题,因为这些事件已经消失了,你需要像这样添加观察者:

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

并检查当它触发时它确实是一个电影播放器​​(因为它也在 UIAlertView 和其他东西上触发):

- (void)ios8EnterFullscreen:(NSNotification *)notification
{
    if ([notification.object isMemberOfClass:[UIWindow class]])
    {
         //do your thing...
    }
}
于 2015-02-20T12:48:10.190 回答