做视频播放的时候,由于要自定义界面,所以使用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];
}
在旋转之后会出现两个状态栏,一个是播放器自带的状态栏(随着播放器的方向改变),另外的是系统的状态栏。
参考这位仁兄的博客 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 的數值外,並需另外新增 View controller-based status bar appearance 欄位,並設定值為 NO。
3.播放时拖拽进度。这个不用流媒体的方式,MPMoviePlayerViewController提供的接口很有限啊,在定制了界面之后,很多不能用系统的播放。
这里有个github上的第三方播放器,不敢独享,https://github.com/alobi/ALMoviePlayerController
以后还要研究的流媒体:http://www.cnblogs.com/ikodota/archive/2012/09/12/compile_ffmpeg_for_iOS.html
好吧先整理到这,功能慢慢完善。欢迎也在做视频的童鞋相互讨论下相关技术