4
votes

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.

4
What exactly you need do you need to be in always the video play in Landscape mode ? is itB25Dec
Yes. I need the video to display only in landscape whether in fullscreen or not.Undistraction
Are you working on iPad or iPhone?marzapower
Why not use AVPlayer and add the AVPlayerLayer to the display view instead of mucking about with MPVideoPlayerController?Steven Veltema
@StevenVeltema If I'd known how buggy MPMoviePlayerController was when I started I would have done and I will most definitely do so on future projects, but I've got this far with it and everything else is now working fine (after an awful lot of work-arounds), so I'm loathe to abandon all that and have to build up all the UI from scratch.Undistraction

4 Answers

2
votes

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).

MyMPMoviePlayerController.view.frame = CGRectMake(0, 0, your numbers, here);

However, Apple, in their docs, says that the controller's frame should be set to the frame of it's parent view.

[MyMPMoviePlayerController.view setFrame: parentView.bounds];

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.

0
votes

yes, i saw you said using MPMoviePlayerViewController is not an option:

still … why not attempt to make MPMoviePlayerViewController of the ViewController that you have that otherwise contains the MPMoviePlayerController and the other items in your view controller. the good part about this is that MPMoviePlayerViewController already has the MPMoviePlayerController built in. you just refer to that instead of the MPMoviePlayerController that you have in your own viewController. that has the shouldAutorotateToInterfaceOrientation that you can override and should do the right thing for you.

-1
votes

You can prepare two videos. If there is no other choice.

-2
votes

Please Visit the link this shows the video only in the landscape mode by default it does so http://mobiledevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html. I hope it will resolve your problem.