MPMoviePlayerController停止在全屏模式下//纵向运行//iOS 7 [英] MPMoviePlayerController stops working in full screen mode // portrait orientation // iOS 7

查看:86
本文介绍了MPMoviePlayerController停止在全屏模式下//纵向运行//iOS 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我使用了嵌入视图,该视图内部具有MPMoviePlayerController.

In my project I use embeded view, which has MPMoviePlayerController inside.

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

This movie player stops working after tapping full screen toggle - it plays 1 more second in full screen mode and then stops and turns back to the inline mode.

这种情况仅在纵向模式下才发生,并且仅在iOS 7上发生-如果我以横向方向打开全屏模式,然后旋转设备,则可以正常工作.

It happens only in portrait mode and only for iOS 7 - if I switch on full screen mode with landscape orientation and then rotate the device, it works alright.

我已经找到原因-某种程度上涉及导航栏.我在项目中使用 ECSlidingViewController ,并在初始化期间设置了半透明的导航栏"NO":

I've found the reason - somehow navigation bar is involved. I use ECSlidingViewController in the project and set up navigation bar translucent "NO" during the initialization:

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

navController.navigationBar.translucent = NO;

self.topViewController = navController;

如果我设置navController.navigationBar.translucent = YES;,电影播放器​​将正常运行.但是我必须半透明=不.

If I set up navController.navigationBar.translucent = YES; the movie player works fine. But I have to have translucent = NO.

因此,我尝试与电影播放器​​一起播放事件MPMoviePlayerWillEnterFullscreenNotification和MPMoviePlayerWillExitFullscreenNotification. 有趣的是,如果我将navBar设为半透明或在进入全屏模式之前将其隐藏,则视频播放的时间会更长一些(大约3-4秒),但是行为是相同的.

So I've tried to play with the movie players events MPMoviePlayerWillEnterFullscreenNotification and MPMoviePlayerWillExitFullscreenNotification. It's interesting that if I make navBar translucent or hide it before entering full screen mode, the video plays a little bit longer (around 3-4 seconds) but then the behavior is the same.

[[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;
} 

任何想法我都可以做到的.

Any ideas what I can do with this are much appreciated.

UPD. 这个错误在iOS 7.0.4中已消失

UPD. This bug is gone in iOS 7.0.4

推荐答案

IMP:如果您使用的是ARC,我认为您需要保留外部moviePlayer.我只是将其分配给自己的新财产.

IMP:If you're using ARC I believe you need to retain the outer moviePlayer. I just assigned it to a new property myself.

我尝试了以下两种方法,并且对我有用.

I tried following two ways and its working for me.

如果您将自己的视图用作整个屏幕.

If your using self view as entire screen.

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];

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

And without using self view you can work with entire fullscreen(it does not invoke the fullscreen-property)

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];

这篇关于MPMoviePlayerController停止在全屏模式下//纵向运行//iOS 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆