Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can be force MPMoviePlayerController to landscape when click on Fullscreen button in iOS

I create a MPMoviePlayerController in detailView(UIVIew), now i want to force MPMoviePlayerController to landscape view when user click on FullScreen button. Can i do that? Please give me any suggestion. Thanks in advance.And this is my code to create :

   NSURL *movieURL = [NSURL URLWithString:previewString];
    movieController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    [movieController.view setFrame:CGRectMake(10,130, 275 , 150)];
    movieController.view.backgroundColor = [UIColor grayColor];
    [detailview addSubview:movieController.view];
    [movieController prepareToPlay];
    movieController.shouldAutoplay = NO;

and willEnterFullscreen () function:

    - (void)willEnterFullscreen:(NSNotification*)notification {
    NSLog(@"willEnterFullscreen");
    donepress = YES;
    // nothing
}

I tried search but still do not have any good answer. Please help me. thanks so much

like image 908
Joson Daniel Avatar asked Sep 13 '13 09:09

Joson Daniel


1 Answers

YES, you can do that with two notification observer to change the full orientation.

First, Add two notification observer to your AppDelegate didFinishLaunchingWithOptions method:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];

Second, Add the method and property

- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = YES;
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = NO;
}

Third, override the supportedInterfaceOrientationsForWindow method, you can return whatever orientation you want

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (self.allowRotation) {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    return UIInterfaceOrientationMaskPortrait;
}
like image 100
JoeyJAL Avatar answered Nov 10 '22 19:11

JoeyJAL