程序员人生 网站导航

记录下用MPMoviePlayerViewController做视频播放的一些问题

栏目:综合技术时间:2015-03-30 08:07:22

做视频播放的时候,由于要自定义界面,所以使用MPMoviePlayerController时,样式用的MPMovieControlStyleNone

进度,音量等用的自己的界面。但是在需要全屏显示的时候,就用到了MPMoviePlayerViewController

以下是点击横屏播放的代码:通过改变view的tranform到达旋转的效果

- (IBAction)showFullScreenClick:(id)sender { isFullScreen = YES; NSString *url = [NSString stringWithFormat:@"%@%@",IMAGE_DOMAIN,[self.data objectForKey:@"content"]]; if (moviePlayerView ==nil) { moviePlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]]; [moviePlayerView.moviePlayer prepareToPlay]; moviePlayerView.view.frame = CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); moviePlayerView.view.center = CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2); CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2); [moviePlayerView.view setTransform:transform]; } [self.view addSubview:moviePlayerView.view]; [self hideStatusBar]; [moviePlayerView.moviePlayer play]; }
在旋转以后会出现两个状态栏,1个是播放器自带的状态栏(随着播放器的方向改变),另外的是系统的状态栏。

参考这位仁兄的博客 http://blog.csdn.net/chchong1234/article/details/24649083?utm_source=tuicool

所以在全屏后,就需要隐藏系统状态栏,返回父视图以后再显示

- (BOOL)prefersStatusBarHidden { return isHiddenStatusBar; } - (void)showStatusBar { isHiddenStatusBar = NO; if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self setNeedsStatusBarAppearanceUpdate]; } } - (void)hideStatusBar { isHiddenStatusBar = YES; if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self setNeedsStatusBarAppearanceUpdate]; } }
这时候候还要在info文件设置两个变量   参考 http://www.cocoachina.com/bbs/read.php?tid=159175

Status bar is initially hidden 的

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐