2011-11-28 39 views
1

我的代码工作正常,直到我将iPhone升级到iOS 5.0。 MPMoviePlayerViewController用于正常工作,但它不适用于iOS 5.0,因此我必须为iOs 5.0和更高版本使用MPMoviePlayerController。它工作正常,但MPMoviePlayerController不像MPMoviePlayerViewController那样自动旋转。iPhone:MPMoviePlayerController不在iOS 5.0上旋转

以下是我的代码。任何人都可以请建议我如何使MPMoviePlayerController代码自动旋转?

-(void)playVideo { 
NSString *filePath = [appDelegate filePath:@"startup.mp4"]; 

if(!appDelegate.iOS5) { 
    // This works perfectly till iOS 4 versions. Rotates automatically 
    MPMoviePlayerViewController *videoController = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:filePath]] autorelease]; 
    [self presentMoviePlayerViewControllerAnimated:videoController]; 
} else { 
    // This doesn't rotate automatically 
    NSURL *url = [NSURL fileURLWithPath:filePath]; 
    MPMoviePlayerController* moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:url] autorelease]; 

    moviePlayer.controlStyle = MPMovieControlStyleDefault; 
    moviePlayer.shouldAutoplay = YES; 
    [self.view addSubview:moviePlayer.view]; 
    [moviePlayer setFullscreen:YES animated:YES]; 
} 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return YES; 
} 

回答

0

尝试对MPMoviePlayerController进行子类化,并强制只将方向设置为纵向。

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 

     return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

不是最好的解决方案,但我想它应该工作。

+0

必须有别的东西。我想知道为什么它旋转MPMoviePlayerViewController(iOS4.0和更早版本),但不是MPMoviePlayerController(iOS5和更高版本)? – applefreak

+0

嗨AppleDevelop,我也面临着同样的问题,在我的情况下,我把我的viewController放在导航控制器上,当视频处于全屏模式时,didRotate没有被调用,因为在正常模式下该方法被调用。如果你已经解决了你的问题plz帮助我... – Dinakar

+0

诺佩哥们。它不工作!你有周围吗? – applefreak