用于MPMoviePlayerViewController的UIDeviceOrientation

时间:2013-06-17 11:20:37

标签: ios mpmovieplayercontroller uideviceorientation

我正在开发一个应用程序,其中我有一个项目列表,我想点击缩略图和视频必须播放,我的要求是只有MPMovieViewController必须旋转剩余的屏幕必须不旋转为此我使用下面的方法在列表中,每次都使它成为肖像。但如果我使用它,我无法旋转MPMoviePlayerViewController。

- (NSUInteger)supportedInterfaceOrientations{

    return (UIInterfaceOrientationMaskPortrait);
}

所以我返回“UIInterfaceOrientationMaskAll”后返回我能够自动旋转MPMoviePlayerViewController但是当我回来点击完成按钮或视频完成后视频处于横向模式然后我的上一个旋转但我不想要那种行为我需要以前的纵向视图,下面是实现MPMoviePlayerViewContoller的代码。

    NSString *filepath   =   [[NSBundle mainBundle] pathForResource:[exeDict objectForKey:@"longVideoName"] ofType:@"mp4"];

    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];

    moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayerController.moviePlayer];

    [moviePlayerController.view setFrame:CGRectMake(0, 0, 320, 480)];

    moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    moviePlayerController.view.userInteractionEnabled =YES;

    [moviePlayerController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationMaskAll];

//    AppDelegate* myDelegate = (((AppDelegate*) [UIApplication sharedApplication].delegate));
//    [myDelegate.window addSubview:moviePlayerController.view];

    MainViewController* mainViewController = (MainViewController*)self.mainViewDelegate;

    [mainViewController presentMoviePlayerViewControllerAnimated:moviePlayerController];

    [moviePlayerController.moviePlayer play];

请告诉我如何获得它。

2 个答案:

答案 0 :(得分:0)

您必须将代码放在viewwillappear()方法中,以便您的列表以纵向模式显示

答案 1 :(得分:0)

- (BOOL)shouldAutorotate
{
    return NO;
}

在mainViewController中实现上面的代码??