【问题标题】:MPMoviePlayerController stops working in full screen mode // portrait orientation // iOS 7MPMoviePlayerController 在全屏模式下停止工作 // 纵向 // iOS 7
【发布时间】:2014-01-21 00:29:37
【问题描述】:

在我的项目中,我使用嵌入式视图,其中包含 MPMoviePlayerController。

此电影播放器​​在点击全屏切换后停止工作 - 它在全屏模式下再播放 1 秒,然后停止并返回内联模式。

它仅在纵向模式下发生,并且仅适用于 iOS 7 - 如果我以横向模式打开全屏模式,然后旋转设备,它就可以正常工作。

我找到了原因 - 不知何故涉及到导航栏。我在项目中使用ECSlidingViewController,初始化时设置导航栏半透明“NO”:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myViewController];

navController.navigationBar.translucent = NO;

self.topViewController = navController;

如果我设置navController.navigationBar.translucent = YES;,电影播放器​​可以正常工作。但我必须有半透明=否。

所以我尝试使用电影播放器​​事件 MPMoviePlayerWillEnterFullscreenNotification 和 MPMoviePlayerWillExitFullscreenNotification。 有趣的是,如果我在进入全屏模式之前使 navBar 半透明或隐藏它,视频播放时间会长一点(大约 3-4 秒),但行为是一样的。

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerWillEnterFullScreen:)
                                                 name:MPMoviePlayerWillEnterFullscreenNotification
                                               object:nil];


-(void)moviePlayerWillEnterFullScreen:(id)sender{

    [self.navigationController setNavigationBarHidden:YES animated:NO]; 

OR
    self.navigationController.navigationBar.translucent = YES;
} 

非常感谢我能做的任何想法。

UPD。 这个错误在 iOS 7.0.4 中消失了

【问题讨论】:

  • 听起来好像导航栏上存在某种类别(伪覆盖)诡计。如果是这种情况,请确保在使用播放器时禁用它,因为它的界面实际上依赖于 UINavigationBar 的上部。如果没有禁用,该类以及 swizzles 上的类别确实会留下一团糟。
  • 感谢 @Till 我检查了项目 - 没有类别或其他导航栏自定义。
  • 这也不包括UINavigationBardrawRect: 代码,对吗?
  • @直到正确。已通过“drawRect:”搜索 - 与 UINavigationBar 没有任何关联(仅 UIScrollView+SVPullToRefresh 和 MDProgressHUD)
  • 无论您的问题是什么,它都不在此处的代码中。在带有 ECSlidingViewController 和 UINavigtionBar 的示例应用程序中,无论方向或导航栏半透明如何,我都可以在两个方向上播放全屏视频。您能否制作一个重现该问题的示例应用程序?

标签: ios objective-c mpmovieplayercontroller


【解决方案1】:

IMP:如果您使用 ARC,我相信您需要保留外部的moviePlayer。我只是自己将它分配给了一个新属性。

我尝试了以下两种方法,它对我有用。

如果您使用本端视图作为整个屏幕。

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform,          CGAffineTransformMakeRotation(M_PI_2));
[moviePlayer.view setFrame: self.view.bounds];
[self.view addSubview: moviePlayer.view];
[moviePlayer play];

并且不使用本端视图,您可以使用整个全屏(它不会调用全屏属性)

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform,   CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[moviePlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:moviePlayer.view];
[moviePlayer play];

【讨论】:

  • @Dmitry Khryukin 如果有帮助。您应该接受答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-18
  • 2013-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多