altair8800
altair8800

Reputation: 11

Youtube Videos force the iOS application to rotate

I created an UIWebView inside an UIViewController. This web view contains a youtube video page like this one: http://www.youtube.com/watch?v=oL1RE8JXaIw

When I click on the video link, the iOS video player is launched. Everything is going well till here.

The problem is that when I rotate my application (in landscape mode) and I click on the done button, my View Controller is in landscape mode.

So I've added this callback in the view controller:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return NO;
}

but nothing has changed.

Any idea?

Upvotes: 1

Views: 818

Answers (3)

Shahid Aslam
Shahid Aslam

Reputation: 2585

I handled that problem using NSNotification like this in viewDidLoad method

[[NSNotificationCenter defaultCenter] addObserver:self
                                     selector:@selector(moviePlayerDidExitFullScreen)
                                         name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                       object:nil];

and this method will call when video ends and you can do necessary changes

- (void)moviePlayerDidExitFullScreen
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationPortraitUpsideDown) 
    {
        [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
    }
}

Hope that Helps

Upvotes: 0

Andrea Mario Lufino
Andrea Mario Lufino

Reputation: 7921

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationPortrait;
}

Upvotes: 0

Tom van der Woerdt
Tom van der Woerdt

Reputation: 29975

That orientation code is invalid - make sure to always return YES for at least one orientation.

Upvotes: 1

Related Questions