2

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];
}
Daniel
  • 17,803
  • 7
  • 74
  • 142

3 Answers3

4

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 :)

4

change

player.controlStyle = MPMovieControlStyleFullscreen; 

to

player.controlStyle = MPMovieControlStyleDefault; 

and in MPMoviePlayerDidExitFullscreenNotification

 [player setControlStyle:MPMovieControlStyleNone];
Vinay
  • 41
  • 1
  • This fixed it for me. I didn't specifically set the controlstyle. Setting it to player.controlStyle = MPMovieControlStyleDefault fixed the "No Video" problem. Thanks ! – bartvdpoel Apr 19 '12 at 20:52
  • I had this issue on iOS6, while iOS5 was working fine. This solution - to set the control style to None - fixed that for me. Thank you! – radiospiel Jan 26 '13 at 00:04
-2
[moviePlayer stop];
[moviePlayer release];
[moviePlayer.view removeFromSuperview]; 
Lefteris
  • 14,002
  • 2
  • 52
  • 90
  • 1
    makes no difference.. Also, isn't it a bit strange to send a message to the view of an object that you just released? – Daniel Oct 17 '11 at 14:50
  • In fact, this solution could cause an error for the reason @dkk suggested. You may find that in certain situations you get crashes. – Dan Hanly Oct 18 '11 at 10:17
  • In fact "addSubview" increases the retain count of the object, so sending release to the control, decreases it's retain count by 1, but it's freed after it's being removed from the Superview. Doing it vice versa doesn't change anything. Thanks for downvoting, without knowing memory management... – Lefteris Oct 18 '11 at 11:31
  • Lol, no worries. You are correct with your addSubview comment, my bad ;) – Dan Hanly Oct 18 '11 at 13:24
  • @Lefteris : the other way around does the same thing. If you removeFromSuperview first, the retain count gets decreased, release decreases one more. It just seems more logical to me to call release last, may be my personal taste. (didn't downvote either :P ) – Daniel Oct 18 '11 at 13:35