Prevent rotation and scaling of MPMoviePlayerController to portrait in full screen mode

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]; 

UIViewController only supports landscape orientation:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { // Return YES for supported orientations. return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight; } 

this correctly blocks rotation only for landscape. However, when I set the MPVideoPlayerController to display full-screen mode, this is ignored and the video is no longer limited to the landscape and rotates to whatever orientation the phone is held in.

How can I prevent the MPMoviePlayerController video from rotating to the portrait orientation in full screen? It is imperative that the video does not rotate when the phone rotates into a portrait.

I tried to subclass MPVideoPlayerController and override shouldAutorotateToInterfaceOrientation: but this has no effect.

MPMoviePlayerController is only one part of the view, so using MPMoviePlayerViewCotroller is absolutely not an option.

+4
source share
4 answers

This seems rather complicated if you really want to avoid using MPMoviePlayerViewController. One option that seems to work even if you have it in full screen mode is to manually set the MPMoviePlayerController view frame. (Note that in other problems with iOS, sometimes using a background view gives different results, but it's worth it.)

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

However, Apple says in its documents that the frame of its parent view should be set in the controller frame.

 [MyMPMoviePlayerController.view setFrame: parentView.bounds]; 

Less elegant solution, but may work even if it is not:

Listen to UIDeviceOrientationDidChangeNotification and watch the movie. Apply the transfrom, borders and center (or frame, etc.) to it so that it still matches the landscape view. Essentially, every time he tries to spin, he converts it back. (It is all assumed that you really cannot keep it from spinning with toAutorotateToInterfaceOrientation :).

The only problem is that he can keep the film in the portrait, but screw with a look that is not the desired result.

+2
source

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

still ... why not try making MPMoviePlayerViewController from the ViewController that you have, which otherwise contains the MPMoviePlayerController and other elements in your view controller. the good part about this is that MPMoviePlayerViewController already has a built-in MPMoviePlayerController. You simply reference this, not the MPMoviePlayerController that you have on your own viewController. which has a mustAutorotateToInterfaceOrientation that you can override and should do the right thing for you.

0
source

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

-1
source

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

-2
source

All Articles