2

I try a lot of things, but I still can't rotate only 1 viewControllor in all my app. I would like to show (or to rotate) in landscape only a vc with a MPMoviePlayerViewController.

Like the videos in Facebook app. The app is only in portrait but video could rotate. After played the video, application return in portrait mode. I'm able to ratate but after "done" videoplayer button clicked the view return in landscape mode.

How can I fix this?

Thank you very much.

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
Tenaciousd93
  • 3,438
  • 4
  • 33
  • 56
  • Refer this url: http://stackoverflow.com/questions/17680867/ios6-landscape-playing-embedded-youtube-video-from-a-uiwebview-within-an-only-po – Siddh Feb 19 '14 at 12:39
  • check: http://stackoverflow.com/questions/7407567/reverting-to-portrait-after-done-pressed-on-movie-player This might help. – z22 Feb 19 '14 at 13:09

2 Answers2

3
  1. Create new View controller for Playing videos

  2. Click on Project then click on Target. In General category under Deployment Info enable All the rotations

  3. Now open your Root view controller and Put following lines.give what orientation of your app

code:

-(BOOL)shouldAutorotate
{
    return TRUE;
}

-(NSUInteger)supportedInterfaceOrientations
{
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    else
    {
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
}

4.Now if you used addsubview method to represent your other ViewController's views then no need to apply orintation methods to other controller. But If any vc you have used PresentController method then add orientation methods to that conroller

jackslash
  • 8,550
  • 45
  • 56
Vishal's p
  • 198
  • 4
  • 19
  • Mmmh, so, if I will have portrait in HomeVC I can use `[self performSegueWithIdentifier:@"myIdentifiew" sender:self];` and set `- (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; }`. But when I will have landscape player, what I have to do? Thanks – Tenaciousd93 Feb 20 '14 at 09:16
  • there is no problem for that, but be sure that you set orientation methods to that vc from where you come to your video playing vc. – Vishal's p Feb 20 '14 at 09:38
  • SUCCESS!!! It works :D I add `supportedInterfaceOrientations` portrait in each VC exempt in `@interface myPlayerViewController : MPMoviePlayerViewController`. If user press "done" button in player, my previous VC come in portrait!!!! Thank you very much +1 and right answer! – Tenaciousd93 Feb 20 '14 at 10:03
2

Create a new UIViewController that you will use for showing a video.

Create a MPMoviePlayerController property

@property (nonatomic, strong) MPMoviePlayerController* moviePlayerController;

Then in viewDidLoad, try this:

 - (void)viewDidLoad
    {
        [super viewDidLoad];

        _moviePlayerController = [[MPMoviePlayerController alloc] init];
        _moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;

        _moviePlayerController.contentURL = [NSURL URLWithString:@"example.com"];

        // Rotating the player to landscape position
        _moviePlayerController.view.frame = CGRectMake(0.0f,
                                            0.0f,
                                            [UIScreen mainScreen].bounds.size.height,
                                            [UIScreen mainScreen].bounds.size.width);

        _moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
        _moviePlayerController.view.center = self.view.center;

        UIView *playerView = _moviePlayerController.view;


        [self.view insertSubview:playerView atIndex:0];
        [_moviePlayerController prepareToPlay];
    }

Hope it helps.

Loukas
  • 616
  • 1
  • 6
  • 22
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • Thanks, this helps me, +1! But I have to edit some code of navigationbar and status bar to get a good result. I will try other solutions before mark as right answer. Thanks – Tenaciousd93 Feb 20 '14 at 09:19