2012-07-10 68 views
1

視頻按鈕位於導航欄的ViewController中,按下後,它將立即以縱向模式顯示視頻。如果我手動旋轉它,它只會在風景中。如何在按下按鈕後立即以橫向模式查看視頻?我需要ViewController處於縱向模式,只有視頻處於橫向模式。如何將視頻自動旋轉到橫向?

這是ViewController.m文件:

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

回答

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)]; 

對於全屏播放使用MPMoviePlayerViewController,然後讓它啓動,並以橫向格式播放使用「shouldAutorotateToInterfaceOrientation」方法對MPMoviePlayerViewController類。

它看起來像這樣:

[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight]; 
+0

我試過使用方法,但它不工作。 – icee 2012-07-10 05:50:08

+0

查看編輯答案 – 2012-07-10 06:17:46

+0

它會變成橫向模式,但視頻仍處於縱向模式。 – icee 2012-07-10 06:30:06

0

請嘗試一下本作ViewController.m並在此的ViewController被推

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

我需要ViewController處於縱向模式,只有視頻處於橫向模式。 – icee 2012-07-10 05:57:23

+0

沒有讓你ViewController是通過你錄製視頻相同的屏幕? – mshau 2012-07-10 06:48:28

+0

ViewController有一個按鈕,在我按下之後,它會轉到視頻。 – icee 2012-07-10 06:59:37

-1

你可以給選項,用戶的天氣圖穿透式他想要在ViewController文件中記錄哪種模式的視頻,然後你可以通過這種方式檢查視頻控制器中的下列情況,這樣你就可以解決你的問題。這對我很有用。

- (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) 
}