Search code examples
iphoneipadmpmovieplayercontroller

MPMoviePlayerController does not respond to setFullscreen = NO


I'm creating a custom MovieController using MPMovieController as base. I can switch the video to full-screen by calling

_[moviePlayer setFullscreen:YES animated:YES];_

Calling the same function ([moviePlayer setFullscreen:NO animated:YES];) to bring the movie-player back to the original state (ie when user press Done button) does not work.

As an alternative, I've also tried to -

a) listening to MPMoviePlayerDidExitFullscreenNotification and calling moviePlayBackDidFinish: function as a result of this.

b) posting my custom notification from inside "Done" function using this -

NSDictionary *thisDictionary = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:MPMovieFinishReasonUserExited] forKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];  
[[NSNotificationCenter defaultCenter] postNotificationName:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer userInfo:thisDictionary];

But in all these cases, the movie-player view does not come back to its original state.

Help Please.

Thanks!


Solution

  • You have to register notification for the event. When you prepare for to play the video, do like this

      [[NSNotificationCenter defaultCenter] addObserver:self 
                            selector:@selector(moviePlayBackDidFinish:) 
                            name:MPMoviePlayerPlaybackDidFinishNotification 
                            object:nil];
    

    and in your moviePlayBackDidFinish selector, do like this

      [[UIApplication sharedApplication] setStatusBarHidden:YES];
      [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification 
            object:nil];
    
    
    [self dismissModalViewControllerAnimated:YES];