views:

235

answers:

1

My iPad app displays a movie full screen using the convenient MPMoviePlayerViewController class. I present it like this:

 [self.hostController presentMoviePlayerViewControllerAnimated:playerViewController];

And later, when notified that playing is done, I dismiss it like this:

 [self.hostController dismissMoviePlayerViewControllerAnimated];

It works fine, except when the user rotates the iPad during movie playback:

1- The iPad is in vertical orientation. My view is vertical. 2- The user starts the movie in vertical orientation. The player is vertical. 3- The user rotates the iPad to the horizontal orientation. 4- The player switches to its horizontal orientation. so far so good. 5- The movie stops, the player is dismissed, my reappears, the iPad is still horizontal, but my view has stayed in the vertical orientation is was in step 1. Now it looks sideways.

Of course, if the user then rotates the iPad, it's back to normal. My view then rotates normally as the iPad rotates.

Did anyone ever encounter that? An easy fix?

Thanks.

+1  A: 

I've encountered this numerous times and it appears to be an Apple bug (and have reported it as such).

The only way (I've found) around this is to listen to UIDeviceOrientationChange and UIApplicationStatusBarOrientationChange notifications. Use the relative timestamp on these notifications; if they both occur within a second of each other, you can be sure that the status bar change is a result of the user switching orientations and not the media SDK changing the status bar orientation. Then, when the movie is finished, you can tell your view controller that it should rotate to landscape.

Jason
hey thanks. But how do you "tell your view controller that it should rotate"? The `UIViewController` `interfaceOrientation` property is read-only.
Jean-Denis Muys
In your example, you should notice your view is in lanscape, but formatted for portrait, and the status bar is actually in the portrait position. All you need to do is call `[[UIApplication sharedApplication] setStatusBarOrientation:trueOrientation]` (landscape, in this example), and your view controller should do the rest.
Jason
Fine it works. Thank you so much.
Jean-Denis Muys