MPMoviePlayerController stops working in full scre

2019-06-21 04:03发布

问题:

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

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.

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.

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;

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

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. This bug is gone in iOS 7.0.4

回答1:

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