1

The video button is in a ViewController at the navigation bar and which after I pressed, it will show the video immediately in portrait mode. It will only be in landscape if i rotate it manually. How do i make the video be viewed in landscape mode immediately after i press the button? I need the ViewController to be in portrait mode and only the video to be in landscape mode.

This is the ViewController.m file:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(IBAction)backbutton
{
    ChapterTableViewController *chapterTable = [self.storyboard instantiateViewControllerWithIdentifier:@"chapterTable"];

    [self.navigationController presentModalViewController:chapterTable animated:YES];
}

-(IBAction)playvideo
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                        pathForResource:@"One Piece Episode 180" ofType:@"mp4"]];

    MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

    [self presentMoviePlayerViewControllerAnimated:playercontroller];
    playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [playercontroller.moviePlayer play];
    playercontroller = nil;
} 

@end
Atulkumar V. Jain
  • 5,102
  • 9
  • 44
  • 61
icee
  • 39
  • 1
  • 9

3 Answers3

0
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

[[self view] setBounds:CGRectMake(0, 0, 480, 320)];
[[self view] setCenter:CGPointMake(160, 240)];
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];

For full screen playback use MPMoviePlayerViewController and then to make it launch and play in landscape format use the "shouldAutorotateToInterfaceOrientation" method on the MPMoviePlayerViewController class.

It looks like this:

[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight];
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
0

Please try this for ViewController.m and also in that view throuth which this ViewController is being Pushed

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Atulkumar V. Jain
  • 5,102
  • 9
  • 44
  • 61
mshau
  • 503
  • 4
  • 19
  • I need the ViewController to be in portrait mode and only the video to be in landscape mode. – icee Jul 10 '12 at 05:57
  • Didnt get you ViewController is the same screen through which you are recording Video? – mshau Jul 10 '12 at 06:48
  • The ViewController has a button in which after i pressed, it is suppose to go to the video. – icee Jul 10 '12 at 06:59
-1

You can give option to user weather he wants to record video in which mode in ViewController file and then you can check following condition in video controller this way you can solve your problem.this worked for me .

- (int)deviceOrientationDidChange
{   
    UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
    int val;
    if (deviceOrientation == UIDeviceOrientationPortrait){
        orientation = AVCaptureVideoOrientationPortrait;
        val=1;
        NSLog(@"AVCaptureVideoOrientationPortrait");
    }
    else if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown){
        orientation = AVCaptureVideoOrientationPortraitUpsideDown;
        val=2;
        NSLog(@"AVCaptureVideoOrientationPortraitUpsideDown");
    }

    // AVCapture and UIDevice have opposite meanings for landscape left and right (AVCapture orientation is the same as UIInterfaceOrientation)
    else if (deviceOrientation == UIDeviceOrientationLandscapeLeft){
        orientation = AVCaptureVideoOrientationLandscapeRight;
        val=3;
        NSLog(@"AVCaptureVideoOrientationLandscapeRight");

    }
    else if (deviceOrientation == UIDeviceOrientationLandscapeRight){
        orientation = AVCaptureVideoOrientationLandscapeLeft;
        val=4;
        NSLog(@"AVCaptureVideoOrientationLandscapeLeft");

    }
    return val;
    // Ignore device orientations for which there is no corresponding still image orientation (e.g. UIDeviceOrientationFaceUp)
}
mshau
  • 503
  • 4
  • 19