首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MPMoviePlayerController在全屏模式//纵向定向// iOS 7下停止工作

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

Stack Overflow用户
提问于 2014-01-21 00:29:37
回答 1查看 1.8K关注 0票数 6

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

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

它只发生在纵向模式和只对iOS 7-如果我打开全屏模式与景观方向,然后旋转设备,它的工作正常。

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

代码语言:javascript
复制
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myViewController];

navController.navigationBar.translucent = NO;

self.topViewController = navController;

如果我设置了navController.navigationBar.translucent = YES;,电影播放器就能正常工作。但我必须有半透明的。

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

代码语言:javascript
复制
[[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中消失了

EN

回答 1

Stack Overflow用户

发布于 2014-01-30 07:21:20

如果你在使用ARC,我认为你需要保留外部moviePlayer。我刚把它分给了一个新的房产。

我试着用两种方法,这对我来说是有用的。

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

代码语言:javascript
复制
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视图,您可以使用整个全屏(它不调用全屏属性)。

代码语言:javascript
复制
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];
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21246918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档