【问题标题】:UIWebView and MPMoviePlayerControllerUIWebView 和 MPMoviePlayerController
【发布时间】:2015-02-17 12:57:01
【问题描述】:
我添加了一个带有 youtube 链接的 web 视图。当用户播放视频时,它默认打开 iOS 电影播放器。我想在该电影播放器退出全屏或播放停止时跟踪它的通知。我已经尝试了 MPMoviewPlayerController 生成的所有通知。他们都没有被解雇。只有当我们启用 MPMoviewPlayerViewCotntroller 对象并从中呈现 MPMoviewPlayer 时,它才会触发。
【问题讨论】:
标签:
iphone
ios7
uiwebview
mpmovieplayercontroller
mpmoviewcontroller
【解决方案1】:
这是因为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...
}
}