Azhar
Azhar

Reputation: 20670

iOS : How to Full screen video when change device orientation to Landscape in MPMoviePlayerController?

I am developing an application with MPMoviePlayerController. The application supports Portrait mode only. But I want to change the video in full Screen when I change the device orientation to landscape and back to half screen when change device orientation to Portrait.

if in Landscape and Full Screen mode and movie finishes then also go to half screen mode.

I have tried different codes and options but could not succeed. please help.

My Source code

@property (nonatomic,strong) MPMoviePlayerController* moviePlayer;

-(void)PlayVideoContent
{
    CGFloat x = 0;
    CGFloat y = 70;
    CGRect mpFrame = CGRectMake(x, y, SCREEN_WIDTH, 200);

    NSString * introVideoFileName = @"video_5.mp4";
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:introVideoFileName ofType:@""]];

    MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
    controller.scalingMode = MPMovieScalingModeAspectFill;

    self.moviePlayer = controller; //Super important
   // controller.view.frame = self.view.bounds; //Set the size
    controller.view.frame = mpFrame; //Set the size
   // [self.moviePlayer setFullscreen:YES animated:YES];

    [self.view addSubview:self.moviePlayer.view]; //Show the view
    [self.moviePlayer play]; //Start playing
}

Upvotes: 0

Views: 1637

Answers (2)

Peter Heide
Peter Heide

Reputation: 519

In your project settings (App Target > General > Deployment Info > Device Orientation), select Portrait, Landscape Left and Landscape Right.

In your root view controller, add:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

If everything gets loaded into this view controller, that should be all you have to do. If you find that some views are rotating when they shouldn't, add this same code to their view controllers.

The controller for the fullscreen video will use the supported orientations specified in the target settings, and so will allow rotation to landscape. When you close the video, the view will rotate back to portrait.

Upvotes: 0

gran33
gran33

Reputation: 12991

U must give the UIViewController(s) of your application to decide whether it's in landscape or portrait.

After that, set all the rest to portrait except the one u want in landscape (the MPMoviePlayerController)

Upvotes: 1

Related Questions