In an iOS5 application for iPhone 4/4s I have a UIViewController with an MPMoviePlayerController view added to its view:
[self.view insertSubview:self.fullscreenMoviePlayerController.view atIndex:2];
The UIViewController only supports landscape orientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
{
// Return YES for supported orientations.
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
this correctly locks rotation to only landscape. However when I set the MPVideoPlayerController to display fullscreen, this is ignored and the video is no longer constrained to landscape and rotates to whatever orientation the phone is held in.
How can I prevent MPMoviePlayerController’s video from rotating to Portrait orientations in fullscreen? It is crucial that the video does not rotate when the phone is rotated to portrait.
I have tried subclassing MPVideoPlayerController and overriding shouldAutorotateToInterfaceOrientation: but this has no effect.
The MPMoviePlayerController is only one part of the view, so using an MPMoviePlayerViewCotroller is absolutely not an option.
This seems to be rather difficult if you really want to avoid using MPMoviePlayerViewController.
One option, that seems to work even if you have it in fullscreen, is to manually set the frame of the MPMoviePlayerController’s view.
(Note that in other iOS issues, sometimes using the background view has produced different results, but it’s worth a shot).
However, Apple, in their docs, says that the controller’s frame should be set to the frame of it’s parent view.
The less elegant solution, but one that might work even if that one doesn’t is this:
Listen for the UIDeviceOrientationDidChangeNotification and take the movie player’s view. Apply a transfrom, bounds, and center (or frame, etc) on it so that it still fits in the landscape view. Essentially transform it back each time it tries to rotate away. (This is all assuming that you really cannot keep it from rotating with shouldAutorotateToInterfaceOrientation:).
The only issue here is that it may keep the movie in portrait but screw around with the view, which is not the desired outcome.