2

Has anything changed in 5.1 which would affect how a MPMoviePlayerViewController works regarding device orientation?

I started getting reports from users today that videos were playing only in portrait mode. I figured out that they were using 5.1 and I quickly upgraded a device to recreate the situation. My code has not changed and works perfectly in 4.x, 5.0, and 5.01.

All the views in my app display in portrait mode except when a user clicks on a video, the movie player is suppose to take over the whole screen and launch into landscape more. The app using the 5.0 SDK but targeting 4.0. Here is the code I am using to display a video:

VideoPlayer *vp = [[VideoPlayer alloc] initWithContentURL:movieURL];
vp.moviePlayer.movieSourceType = src;
vp.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
vp.moviePlayer.shouldAutoplay = TRUE;
[self presentMoviePlayerViewControllerAnimated:vp];

VideoPlayer is a subclass of MPMoviePlayerViewController where the shouldAutorotateToInterfaceOrientation is overridden like so:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIDeviceOrientationLandscapeLeft);
}

This pattern is recommended all over the internet and even by Apple. I don't understand why its not working under iOS 5.1 or why more people aren't complaining about this.

Any help will be greatly appreciated.

twktue
  • 71
  • 1
  • 6
  • I have the same problem, not with a movieplayer but just with a normal viewcontroller, it displays it in portrait mode , but the shoudlAutorotate method returns NO on portrait mode, if you have a solution please do post it :) – Andy Jacobs Mar 09 '12 at 12:14
  • I haven't found a solution yet. The sucky thing is that I created a new project and set up this basic pattern and it works perfectly. So...I am thinking that it has something to do with the view hierarchy i have setup in the production application. This seems more like a bug with 5.1 than my code because this has been working perfectly since 3.x. – twktue Mar 10 '12 at 20:30

3 Answers3

2

I had the same problem also - i was playing the movie on a opengl subview, (im making an interactive ebook in landscape mode so needed my movie - (in a uiview) to play in landscape also)

I corrected this by: subclassing the open glview to a *viewcontroller then linking that *viewcontroller to the window

So while working with cocos2d i can now use all uikit in the correct orientation. Sending all uikit views to my subclasses opengl view. (while making sure to add in my app delegate and checking that orientation is stated in plist too.)

"#if GAME_AUTOROTATION == kGameAutorotationUIViewController
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
"#else
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
"#endif

hope this helps someone :) im very new at cocos2d so it took a while to figure out what i was doing wrong.

EBarr
  • 11,826
  • 7
  • 63
  • 85
StackBuddy
  • 577
  • 5
  • 17
1

I had the same issue in iOS 5. The only way I was able to get it to work was to subclass MPMoviePlayerViewController.

@implementation MovieViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    } else {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
} 
@end

It looks you have already tried to do this, but this block of code is working for me on the device with iOS 5.1. Not sure about the simulator.

James Jones
  • 1,486
  • 1
  • 12
  • 22
0

I had a bunch of orientation issues after upgrading to iOS 5.1. For me, it was because the allowed orientations of sibling viewcontrollers up the chain resulted in no allowable orientation for a modal controller I was adding.

Do you have any cases in your view hierarchy where two subviews are added to a view? I was adding two subviews to my window in applicationDidFinishLaunching, and before iOS 5.1, they could have independent allowable orientations. ie, I could have one fixed in portrait orientation while the one on top rotated. Now, the other subview insists on portrait orientation.

My solution was to force the non-rotating view below:

[self.window insertSubview:self.nonRotatingViewController.view belowSubview:self.rotatingViewController.view];

This post helped me figure that out (and has some code): iOS: Disable Autorotation for a Subview

Community
  • 1
  • 1
mikewoz
  • 146
  • 2
  • 9