Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController fullscreen quirk in iPad

I want to show a MPMoviePlayerController in a view controller and let the user toggle full screen with the default controls, like the YouTube app. I'm using the following code in a bare-bones example:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.player = [[MPMoviePlayerController alloc] init];
    self.player.contentURL = theURL;
    self.player.view.frame = self.viewForMovie.bounds;
    self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.viewForMovie addSubview:player.view];
    [self.player play];
}

This works well until the user makes the video full screen, rotates the device and taps on the screen. The status bar is shown in the wrong position, as shown in the screenshot below.

screenshot

I'm working with the template Tab Bar Application for iPad. I've only added the viewDidLoad above, the view variables and an UIView in the XIB to show the movie player.

What am I doing wrong?

like image 248
hpique Avatar asked May 17 '10 21:05

hpique


People also ask

Can I use mpmovieplayercontroller in iOS 9?

The MPMoviePlayerController class is formally deprecated in iOS 9. (The MPMoviePlayerViewController class is also formally deprecated.) To play video content in iOS 9 and later, instead use the AVPictureInPictureController or AVPlayerViewController class from the AVKit framework, or the WKWebView class from WebKit.

How to detect changes in fullscreen mode of a movie player?

Use the MPMoviePlayerWillEnterFullscreen and MPMoviePlayerWillExitFullscreen notifications to detect changes to and from fullscreen mode. This class supports programmatic control of movie playback, and user-based control via buttons supplied by the movie player.

How do I play video content in iOS 9 and later?

(The MPMoviePlayerViewController class is also formally deprecated.) To play video content in iOS 9 and later, instead use the AVPictureInPictureController or AVPlayerViewController class from the AVKit framework, or the WKWebView class from WebKit. Playback occurs in a view owned by the movie player and takes place either fullscreen or inline.

How do I manage a movie player’s view?

You can incorporate a movie player’s view into a view hierarchy owned by your app, or use an MPMoviePlayerViewController object to manage the presentation for you. Movie players support wireless movie playback to AirPlay-enabled hardware such as Apple TV.


2 Answers

Yeah, I'm experiencing this problem as well. It definitely appears to be a bug in the MPMoviePlayerController itself.

The workaround I've settled on in my application is to just correct the status bar myself when I exit fullscreen mode:

- (void)playerDidExitFullscreen:(NSNotification *)notification {
    MPMoviePlayerController *moviePlayer = (MPMoviePlayerController *) notification.object;

    if (moviePlayer == self.player) {
        UIApplication *app = [UIApplication sharedApplication];
        if (app.statusBarOrientation != self.interfaceOrientation) {
            [app setStatusBarOrientation:self.interfaceOrientation animated:NO];
        }
    }
}

This doesn't fix the problem while in fullscreen mode, but it does fix it afterwards.

Note of course that the function needs to be added to the notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
like image 130
Richard Venable Avatar answered Nov 09 '22 05:11

Richard Venable


Is shouldAutorotateToInterfaceOrientation:interfaceOrientation returning YES for all of the supported orientations?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

If you provided more of your code it would help.

like image 37
smountcastle Avatar answered Nov 09 '22 04:11

smountcastle