0
votes

In my project,i have set orientation lock so that it should run only in portrait mode.I want the mpMoviePlayer to rotate it to landscape mode once rotated to landscape and then remain in the landscape mode until the user click "done " button.

Now the player will rotate to landscape in fullscreen and when we rotate back to portrait mode,the player will rotate back to portrait mode in full screen and any further rotations are not effected to the player.It will remain in portrait fullscreen mode.

Any idea??

this is my requirement..:I want the mpMoviePlayer to rotate it to landscape mode once rotated to landscape and then remain in the landscape mode until the user click "done " button.

any suggestion??Thanks in advance..

2

2 Answers

1
votes

First of all put this in your ViewController that plays the video:

- (BOOL)shouldAutorotate
{
    return YES;
}

Then implement methods that force the desired orientation or whatever orientations you want:

- (void)forceOrientationPortrait
{
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationPortrait] forKey:@"orientation"];
}

- (void)forceOrientationLandscape
{
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];
}

Last you add observers for when the MoviePlayer goes fullscreen and when it exits. The observers trigger the before mentioned orientation change methods:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forceOrientationLandscape) name:MPMoviePlayerDidEnterFullscreenNotification object:Nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forceOrientationPortrait) name:MPMoviePlayerDidExitFullscreenNotification object:Nil];
}

All put together it should look like this:

completecode

I hope with this you can accomplish your goals.

-- edit --

If you want to lock the orientation after forcing the device to portrait/landscape then you could implement a Boolean that sets the ShouldAutorotate method accordingly. Try something like this:

orientationBoolean

0
votes

I guess you have to unlock orientations for the app. And use supportedInterfaceOrientations method in all viewControllers to lock the orientation to portrait. create your own mpPlayerVC based on e.g.MPMoviePlayerViewController and override the same method with landscape.