强制MPMoviePlayerController在横向中播放

时间:2011-04-26 14:17:47

标签: iphone cocoa-touch ios

我是iPhone开发新手并编写我的第一个应用程序。整个应用程序只需要肖像模式,但播放电影除外。我正在使用MPMoviePlayerController启动电影,它以protrait模式播放。如何强制MPMoviePlayerController播放Landscape中的所有电影。 我正在使用Xcode 4并构建iOS 4.0+。我是否需要在info.plist中输入一些设置以允许MPMoviePlayerController以横向播放?

以下是我用来初始化MPMoviePlayerController的代码:

MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL: url]; 
[self.view addSubview:theMovie.view];
theMovie.allowsAirPlay=YES;
[theMovie setFullscreen:YES animated:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie play]; 

2 个答案:

答案 0 :(得分:6)

将播放器嵌入其自己的视图控制器中并按如下方式实现shouldAutorotateToInterfaceOrientation

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

答案 1 :(得分:0)

制作MPMoviePlayerViewController的子类:

@interface MyMoviePlayerViewController ()

@end

@implementation MyMoviePlayerViewController

- (BOOL)shouldAutorotate { return NO; }
- (NSUInteger)supportedInterfaceOrientations {
  return UIInterfaceOrientationMaskLandscape;
}

@end