在我的项目中,我使用了嵌入式视图,其中包含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.这个bug在iOS 7.0.4中消失了
发布于 2014-01-30 07:21:20
如果你在使用ARC,我认为你需要保留外部moviePlayer。我刚把它分给了一个新的房产。
我试着用两种方法,这对我来说是有用的。
如果您使用self视图作为整个屏幕。
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];而且,不使用self视图,您可以使用整个全屏(它不调用全屏属性)。
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];https://stackoverflow.com/questions/21246918
复制相似问题