iPhone:MPMoviePlayerController在iOS 5.0上不会旋转

时间:2011-11-28 14:27:11

标签: iphone ios5 mpmovieplayercontroller

我的代码工作正常,直到我将iPhone升级到iOS 5.0。 MPMoviePlayerViewController以前工作正常但它在iOS 5.0上不起作用所以我必须使用MPMoviePlayerController用于iOs 5.0及更高版本。它工作正常,但MPMoviePlayerController不会像以前那样自动旋转MPMoviePlayerViewController。

以下是我的代码。任何人都可以建议我如何使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;
}

1 个答案:

答案 0 :(得分:0)

尝试继承MPMoviePlayerController并将方向强制为仅限纵向。

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

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

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