MPMoviePlayerController全屏问题(显示黑屏) [英] MPMoviePlayerController in full screen issue (showing blank black screen)

查看:74
本文介绍了MPMoviePlayerController全屏问题(显示黑屏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含几个页面的tabBarViewController和一个loginViewController.我使用[window addSubView:]添加视图.

I have tabBarViewController which contain few pages, and a loginViewController. I use [window addSubView:] to add the views.

当我需要播放全屏视频时,我必须删除窗口中的所有视图才能显示视频,否则,它只是一个黑屏.当视频停止/完成/退出全屏播放时,我必须手动将子视图重新添加回窗口.

When I need to play fullcreen video, I have to remove all the view in window in order to displaying the video, else, it is just a black screen. When the video is stop/finished/exitFrom full screen, I have to manually add the subview back again to window.

我知道这是错误的做法.如果我不这样做,当视频切换到全屏时,它将以根窗口视图的形式显示在其他视图的后面.

I know this is a wrong way of doing it. If I'm not doing this way, when video is switched to full screen, it will display in root window view, at the back of other views.

请提供一些建议.谢谢.

Please give some advices. Thank you.

下面是我的代码:

-(void)playMovie:(NSString *)urlStr{
NSURL *fileURL = [NSURL URLWithString:urlStr];
player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
player.scalingMode = MPMovieScalingModeAspectFit;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullscreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];    
[[appDelegate loginViewController].view removeFromSuperview];
[[appDelegate tabBarController].view removeFromSuperview];
[[appDelegate navController].view addSubview:player.view];
player.fullscreen = YES;
[player play];

}

- (void)willExitFullscreen:(NSNotification*)notification {
NSLog(@"willExitFullscreen...");
[[appDelegate window] addSubview:[appDelegate navController].view];
[[appDelegate window] addSubview:[appDelegate loginViewController].view];
[[appDelegate window] addSubview:[appDelegate tabBarController].view];
[player.view removeFromSuperview];

}

推荐答案

要演示播放器,请使用:

To present the player use:

[self presentMoviePlayerViewControllerAnimated:player]; 
//Self should be a View Controller.

而不是使用addSubview.

此外,还应确保在player上设置movieSourceType(可通过player.moviePlayer进行访问),并建议使用player.view.backgroundColor = [UIColor blackColor];设置播放器背景,以避免闪烁白色背景.

Also, you should make sure to set the movieSourceType on your player (which you can access via player.moviePlayer), and as a recommendation set the player background using player.view.backgroundColor = [UIColor blackColor]; to avoid a flashing white background.

这篇关于MPMoviePlayerController全屏问题(显示黑屏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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