0

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..

abhimuralidharan
  • 5,752
  • 5
  • 46
  • 70

2 Answers2

1

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

Michael
  • 997
  • 1
  • 7
  • 13
  • forceOrientationLandscape methodn is called once when the player enters landscape mode.After that if the device is rotated to portrait,the player will be rotated to portrait fullscreen.then if we rotate it to landscape again,the forceOreintation method is not called. Also,the forceOrientationPortrait method is called for the first time when we click the done button only. – abhimuralidharan Apr 01 '15 at 12:02
  • You should code something yourself ;). Please look at the edited answer with added explanation for locking device orientation after forcing one for the user. If my answer was useful, please mark it a such. – Michael Apr 01 '15 at 12:55
  • http://stackoverflow.com/questions/29446016/how-to-handle-the-back-buttonios-8-2-in-iphone @michael,can u help me with this? – abhimuralidharan Apr 04 '15 at 11:50
0

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.

kabarga
  • 803
  • 6
  • 11