【问题标题】:iPhone: MPMoviePlayerController doesn't rotate on iOS 5.0iPhone:MPMoviePlayerController 在 iOS 5.0 上不旋转
【发布时间】:2011-11-28 14:27:10
【问题描述】:

在我将 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;
}

【问题讨论】:

    标签: iphone ios5 mpmovieplayercontroller


    【解决方案1】:

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

    - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    
          return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
    

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

    【讨论】:

    • 肯定还有别的。我想知道为什么它正在旋转 MPMoviePlayerViewController(iOS4.0 及更早版本)而不是 MPMoviePlayerController(iOS5 及更高版本)?
    • 嗨 AppleDevelop,我也面临同样的问题,在我的情况下,我将 viewController 放在导航控制器上,当视频处于全屏模式时,DidRotate 没有被调用,因为方法正在获取在正常模式下调用。如果你解决了你的问题,请帮助我......
    • 我必须遵循 -stackoverflow.com/questions/9572640/… 中提到的不同方法,它对我有用!
    • 如果您有基于选项卡的应用程序并且每个选项卡为 shouldAutorotateToInterfaceOrientation 返回 true,则 Yorxxx 答案有效,否则它们都不会自动旋转。你可能想看看“为什么我的 UIViewController 不旋转 - developer.apple.com/library/ios/#qa/qa1688/_index.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    相关资源
    最近更新 更多