Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerViewController doesn't auto-rotate

Tags:

I'm having some strange behavior where my MPMoviePlayerViewController isn't auto-rotating when the orientation changes. However, I recreated the same view hierarchy in a fresh project and when the MPMoviePlayerViewController player was up, it rotated to every orientation. I've scoured the project looking for anything that might be setting the orientation explicitly, but there is nothing.

I'll lay out all the relevant information here and the things that I've tried so far.

The view hierarchy currently looks like this:

  • Navigation Controller
  • "Root" View Controller <- navigation controller's 'rootViewController'
  • "Feed" View Controller <- Pushed on the navigation stack by the Root VC
  • "Preview" View Controller <- Presented as a modal VC from the Feed
  • MPMoviePlayerViewController Subclass <- presented by the Feed VC via 'presentMoviePlayerViewControllerAnimated'

Every class in the view hierarchy responds to shouldAutorotateToInterfaceOrientation with YES only for UIInterfaceOrientationPortrait.

Things I've tried:

  • Manually sending the shouldAutorotateToInterfaceOrientation up stack from the "Root" VC up to the MPMoviePlayerViewController
  • Overriding the MPMoviePlayerViewController subclass' implementation of shouldAutorotateToInterfaceOrientation to return YES for both landscape orientations and YES for all orientations.
  • Setting 'Supported Device Orientation' in the project's summary tab.
  • Calling the presentMoviePlayerViewControllerAnimated from other VCs like the Feed VC

If the movie player properly rotates in a fresh project with same view hierarchy, what could possible be getting in the way here. Any ideas as to where the orientation might be getting stuck?

like image 269
dzl Avatar asked May 21 '12 18:05

dzl


3 Answers

I will suggest you not to use presentMoviePlayerViewControllerAnimated, rather than add as subview. I think it will fix your problem nicely.

MPMoviePlayerViewController *mpviewController = [[MPMoviePlayerViewController alloc]
                    initWithContentURL:[NSURL fileURLWithPath:self.filePath]];
[self.view addSubview:mpviewController.view];
[self setWantsFullScreenLayout:YES]; 

And remove the mpviewController.view when MPMoviePlayerPlaybackDidFinishNotification detected. Let me see your success...

like image 99
kallol Avatar answered Oct 17 '22 17:10

kallol


I've found that MPMoviePlayerViewController objects will honor the project's Info.plist settings for supported interface orientations. In a project of mine I was only allowing landscape views in that file so the movie player will not rotate, even when it answered YES to landscape orientations in shouldAutorotateToInterfaceOrientation:.

Edit: OK, grasping at straws: Do you implement automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers in any of your UIViewController subclasses? If so, and it returns NO, your subclasses must forward the appropriate methods to any child controllers upon orientation change.

Otherwise is there any way to see your code?

like image 42
Mr. Berna Avatar answered Oct 17 '22 17:10

Mr. Berna


I know this might be a stupid suggestion but make sure that the shouldAutorotateToInterfaceOrientation method in your MPMoviePlayerViewController subclass is getting called. Maybe something went wrong there...

Also make sure that you don't have 2 subviews added to the main UIWindow as specified here:

Q: Why won't my UIViewController rotate with the device?

[...]

  • The view controller's UIView property is embedded inside UIWindow but alongside an additional view controller.

I think that might give you some problems too. You can find more information about what could go wrong in the link above.

like image 45
Mihai Fratu Avatar answered Oct 17 '22 19:10

Mihai Fratu