问题
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.
Below is my code:
-(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];
}
回答1:
To present the player use:
[self presentMoviePlayerViewControllerAnimated:player];
//Self should be a View Controller.
rather than using addSubview
.
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.
来源:https://stackoverflow.com/questions/11043922/mpmovieplayercontroller-in-full-screen-issue-showing-blank-black-screen