jakife jakife - 1 year ago 113
Objective-C Question

How do I make my MPMoviePlayerController Play in Landscape?

I am trying to make my video from youtube play in landscape mode. I turned off landscape left and right for supported device orientation because if it was on, every view is able to go landscape. I'm building this for iOS 6. How do I make my video play in landscape.

Here is my code

#import "VideoTViewController.h"
#import "HCYoutubeParser.h"
#import <MediaPlayer/MediaPlayer.h>

@interface VideoTViewController ()


@implementation VideoTViewController
@synthesize tLabel;


NSDictionary *videos = [HCYoutubeParser h264videosWithYoutubeURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=zz_bJ58LfCg&feature=youtu.be"]];

MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[videos objectForKey:@"medium"]]];

[self presentViewController:mp animated:YES completion:nil];


I did the following:

Made a new class

AboutNavViewController (which subclasses a UiNavigationController)

#import "AboutNavViewController.h"

@interface AboutNavViewController ()


@implementation AboutNavViewController

- (BOOL)shouldAutorotate {
return NO;

- (BOOL)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;

And in my aboutviewcontroller (which subclasses a uiviewcontroller)

#import "AboutViewController.h"
#import "AboutNavViewController.h"

@interface AboutViewController ()


@implementation AboutViewController
@synthesize aLabel;

- (void)viewDidLoad
[super viewDidLoad];

CGRect frame = CGRectMake(0, 0, 320, 44);
aLabel = [[UILabel alloc] initWithFrame:frame];
aLabel.backgroundColor = [UIColor clearColor];
[aLabel setFont:[UIFont fontWithName:@"SerifGothic LT Black" size:25]];
aLabel.text = @"Sephardi Jews";
aLabel.textAlignment = NSTextAlignmentCenter;
aLabel.textColor =[UIColor whiteColor];
self.navigationItem.titleView = aLabel;

AboutNavViewController *about = [[AboutNavViewController alloc] init];

[self presentViewController:about animated:YES completion:nil];

- (void)viewDidUnload
[super viewDidUnload];
// Release any retained subviews of the main view.


I get the following error:

Unbalanced calls to begin/end appearance transitions for .

What am I doing wrong?

Answer Source

Note: You must add landscape left and right to your supported interface orientations in Info.plist for this to work.

The system determines whether an orientation is supported by intersecting the value returned by the app’s supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller.

Added iOS 6 autorotation methods from previous answer"

@interface MyMovieViewController : MPMoviePlayerViewController

@implementation MyMovieViewController

- (BOOL)shouldAutorotate 
    return YES;

- (NSInteger)supportedInterfaceOrientations 
    return UIInterfaceOrientationMaskLandscape;

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download