MPMoviePlayerController not closing on iOS5.0

4k views Asked by At

I start a MPMoviePlayerController in fullscreen mode, and then close it with the default buttons. It works like a charm on iOS4.3 but leaves a black screen on iOS5.0 :(

Am I doing something wrong? here is my code:

To show the player:

- (void)showVideo {

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL];  

// Register to receive a notification when the movie has finished playing.  
[[NSNotificationCenter defaultCenter] addObserver:self  
                                         selector:@selector(moviePlayBackDidFinish:)  
                                             name:MPMoviePlayerPlaybackDidFinishNotification  
                                           object:moviePlayer];      



moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.shouldAutoplay = YES;  
moviePlayer.view.frame = [[UIScreen mainScreen] applicationFrame];
moviePlayer.view.transform = CGAffineTransformMakeRotation(1.57079633);    

[self.view addSubview:moviePlayer.view];  

[moviePlayer setFullscreen:YES animated:NO];  
}

To close the player:

- (void) moviePlayBackDidFinish : (NSNotification *) notification
{
MPMoviePlayerController *moviePlayer = [notification object];  
[[NSNotificationCenter defaultCenter] removeObserver:self  
                                                name:MPMoviePlayerPlaybackDidFinishNotification  
                                              object:moviePlayer];  

[moviePlayer.view removeFromSuperview];

[moviePlayer stop];
[moviePlayer release];  

//otherwise the status bar hides or changes color from time to time 
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
3

There are 3 answers

5
SpittingLlama On BEST ANSWER

I've been trying to solve the same problem after updating to iOS5.

  • this is what I'm come up with so far:

It's a bug in the MPMoviePlayerController after going into fullscreen mode. Basically you can't leave the fullscreen mode. But this should be solved if we just remove the MPMoviePlayerController. But no luck there...

Could it be that the main view doesn't start redrawing after going to full screen with the video player? (Pausing redrawing of the views under de fullscreen should improve performance of video playback. And as far as I know this should be the case.)

  • Here is a solution: (tkx go to my college who had the original problem)

Don't go into fullscreen mode and just stretch the MPMoviePlayerController to the parent views bounds. The problem here is that if we rotate our screen the automatic rotation that the fullscreen mode gave is doesn't get used.

//instead of going to fullscreen
//[moviePlayer setFullscreen:YES animated:YES];    
[moviePlayer.view setFrame:self.view.bounds];

//when the movie has finished playing release it
  • Solution to the rotation problem:

Write rotation code :)

5
Lefteris On
[moviePlayer stop];
[moviePlayer release];
[moviePlayer.view removeFromSuperview]; 
2
Vinay On

change

player.controlStyle = MPMovieControlStyleFullscreen; 

to

player.controlStyle = MPMovieControlStyleDefault; 

and in MPMoviePlayerDidExitFullscreenNotification

 [player setControlStyle:MPMovieControlStyleNone];