如何在iOS中运行MPMoviePlayerViewController时禁用FULLScreen模式

时间:2013-09-16 04:08:47

标签: ios objective-c mpmovieplayercontroller

我遇到了问题:我向MPMoviePlayerViewController添加了detailView,但是当我点击按钮打开detailView时,MPMoviePlayerViewController会自动在FUllScreen模式下播放。现在我想要点击按钮打开DetailViewMPMoviePlayerViewController显示播放按钮而不是自动播放。然后用户单击“播放”按钮,MPMoviePlayerViewController必须通过调用[self presentMoviePlayerViewControllerAnimated:moviePlayer];在FULLScreen中运行。我怎样才能做到这一点?提前谢谢。

movieURL = [NSURL URLWithString:previewString];

    moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
    moviePlayer.view.frame = CGRectMake(10,130, 275 , 150);
    [moviePlayer.moviePlayer prepareToPlay] ;
    moviePlayer.moviePlayer.shouldAutoplay = NO;
    moviePlayer.wantsFullScreenLayout = NO;
    moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    //[detailview addSubview:moviePlayer.view];
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];

如果尝试上面的代码,moviePlayer会自动在FULLSCREEN模式下运行。现在我想在开始时,moviePlayer不会在FULLSCREEN模式下自动运行,当用户点击Play按钮时,它将以FULLSCREEN模式运行。

1 个答案:

答案 0 :(得分:1)

要求通知播放状态已更改:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(mpChangedPlaybackState:)
                                             name:MPMoviePlayerPlaybackStateDidChangeNotification
                                           object:nil];

然后检查播放状态以查看它是否正在播放:

- (void)mpChangedPlaybackState:(NSNotification *)notification {

    if (self.moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
        // the state has changed to 'playing'
    }
}

当你不再需要知道时(最迟在viewWillDisappear:上)

,请记得以观察者身份移除自己