Ricky Park
Ricky Park

Reputation: 256

"Done" button in MPMoviePlayerController doesn't work when full screen mode

Well, I could find many questions about the same or similar questions and answers... However, nothing could help me. Only when I don't use the property "controlStyle" as "MPMovieControlStyleFullscreen", "done" button works. I tried this way..

    MPMoviePlayerController *mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
    mpMoviePlayerController.controlStyle = MPMovieControlStyleNone;
    [mpMoviePlayerController setUseApplicationAudioSession:NO];
    [mpMoviePlayerController setScalingMode:MPMovieScalingModeAspectFit];
    [mpMoviePlayerController setFullscreen:YES animated:YES];
    [mpMoviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 768)];

    [[globalSingleton paintingView] addSubview:mpMoviePlayerController.view];

    [mpMoviePlayerController prepareToPlay];
    [mpMoviePlayerController play];

    mpMoviePlayerController.controlStyle = MPMovieControlStyleFullscreen;

or this way..

    MPMoviePlayerController *mp;
    MPMoviePlayerViewController *mpVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
    mp = [mpVC moviePlayer];
    mp.controlStyle = MPMovieControlStyleFullscreen;
    mp.fullscreen = NO;
    mp.useApplicationAudioSession = NO;
    mp.view.frame = CGRectMake(0, 0, 1024, 768);

    [[globalSingleton paintingView] addSubview:mp.view];

([globalSingleton paintingView] is just for representing main view. I already checked there's no problem on it.)

Please share what u know about this problem. Thx in advance!

Upvotes: 0

Views: 7143

Answers (1)

Wes
Wes

Reputation: 1686

Based on your code, It looks to me that your intention is to just have a fullscreen movie player take over the screen. In that case, you're probably better off using the MPMoviePlayerViewController, but you need to present it as a modal view controller using your current view controller like this:

MPMoviePlayerViewController *movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:someVideoURL];
movieViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

// Self is the UIViewController you are presenting the movie player from.
[self presentMoviePlayerViewControllerAnimated:movieViewController];

The "Done" button should work properly in this case, and dismiss the modal MPMoviePlayerViewController

On the other hand, If you're more interested in animating the movie from where you've added it in the current view hierarchy, here is an example of what I have done to achieve this:

I also found that setting the MPMoviePlayerController's controlStyle property to MPMovieControlStyleFullscreen had the same result–the "Done" button did not close the MPMoviePlayerController. When I changed it to MPMovieControlStyleDefault, it worked as expected. However, in my case, I'm adding the MPMoviePlayerController's view as a thumbnail-sized subview to the currently displayed UIViewController's view. I initially have the MPMoviePlayerController's controlStyle set to MPMovieControlStyleNone. I have a custom UIButton on top of the thumbnail-sized movie player view, and in the button's action method, I'm changing the controlStyle of the MPMoviePlayerController to MPMovieControlStyleDefault, then calling setFullscreen:animated: which animates the movie player view into fullscreen mode. Then, tapping the "done" button properly animates the player back into place in the thumbnail-sized subview of my UIViewController's view. Here is an example:

Initial instantiation of my MPMoviePlayerController:

// My moviePlayerController is a property
self.moviePlayer = [[MPMoviePlayerController alloc] initWithURL:videoURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.shouldAutoplay = NO;


// Add the moviePlayer's view as a subview of a my UIViewController's view.
moviePlayer.view.frame = CGRectMake(20, 20, 160, 90);
[self.view addSubview:moviePlayer.view];

Note: I also added a custom UIButton (to invoke fullscreen playback) on top of my moviePlayer's view and set it's action to call the following method:

- (void)buttonAction:(UIButton *)sender
  {
      self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
      [self.moviePlayer setFullscreen:YES animated:YES];
      [self.moviePlayer play];
  }

Note: I also observe and handle the MPMoviePlayerWillExitFullscreenNotification where I set the controlStyle back to MPMovieControlStyleNone.

Upvotes: 3

Related Questions