iPhone SDK 4:来自MPMoviePlayerViewController的视频自动旋转

时间:2010-08-14 04:51:57

标签: iphone cocoa-touch video

您能否在MPMoviePlayerViewController中显示shouldAutorotateToInterfaceOrientation方法用法的示例?据我所知,使用shouldAutorotateToInterfaceOrientation方法不仅适用于UIView,也适用于自SDK 3.2以来的MPMoviePlayerViewController。我一直在UIView中使用它,在3.1中,但我不明白如何在MPMoviePlayerViewController类中使用它。

这就是我现在所拥有的:

-(IBAction) playMovie {

//declaring path to file and stuff...

    MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(moviePlayBackDidFinish:)
                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                   object:[playerViewController moviePlayer]];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];      

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

    - (void)moviePlayBackDidFinish:(NSNotification*)notification {
        MPMoviePlayerViewController *moviePlayer = [notification object];
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:MPMoviePlayerPlaybackDidFinishNotification
                                                      object:moviePlayer];

        [moviePlayer.view removeFromSuperview];

        [moviePlayer release];  
    }

它工作正常,但我需要知道如何实现视频自动旋转。在UIView中使用它的方法没有帮助。

感谢。

1 个答案:

答案 0 :(得分:0)

嗯,听起来很奇怪,但我确信这个方法一定不能在播放Movie块之外声明。我错了,下面的代码像往常一样粘贴,它可以满足我的需要。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationPortrait ||
        interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        return YES;
    else {
        return NO;
    }

}