UIWebView 和 MPMoviePlayerController
UIWebView and MPMoviePlayerController
我添加了一个包含 YouTube 的网络视图 link。当用户播放 viedo 时,它默认打开 iOS 电影播放器。我想跟踪该电影播放器退出全屏或播放停止时的通知。我已经尝试了 MPMoviewPlayerController 生成的所有通知。 None 人被解雇了。它仅在我们初始化 MPMoviewPlayerViewCotntroller 对象并从中呈现 MPMoviewPlayer 时才会启动。
那是因为 UIWebView
中的 Youtube 视频不是 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...
}
}
我添加了一个包含 YouTube 的网络视图 link。当用户播放 viedo 时,它默认打开 iOS 电影播放器。我想跟踪该电影播放器退出全屏或播放停止时的通知。我已经尝试了 MPMoviewPlayerController 生成的所有通知。 None 人被解雇了。它仅在我们初始化 MPMoviewPlayerViewCotntroller 对象并从中呈现 MPMoviewPlayer 时才会启动。
那是因为 UIWebView
中的 Youtube 视频不是 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...
}
}