MPMoviePlayerController在全屏模式下停止工作//纵向// iOS 7

Dmi*_*kin 6 objective-c mpmovieplayercontroller ios

在我的项目中,我使用嵌入式视图,里面有MPMoviePlayerController.

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

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

我找到了原因 - 不知何故涉及导航栏.我在项目中使用ECSlidingViewController并在初始化期间设置半透明的"NO"导航栏:

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

navController.navigationBar.translucent = NO;

self.topViewController = navController;
Run Code Online (Sandbox Code Playgroud)

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

所以我试着玩电影播放器​​事件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;
} 
Run Code Online (Sandbox Code Playgroud)

我对此能做的任何想法都非常感激.

UPD. 这个bug在iOS 7.0.4中消失了

pyt*_*hon 3

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];
Run Code Online (Sandbox Code Playgroud)

并且无需使用自身视图,您就可以使用整个全屏(它不会调用全屏属性)

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];
Run Code Online (Sandbox Code Playgroud)