1

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

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 会自动以全屏模式运行。现在我想在开始时,moviePlayer 不会在全屏模式下自动运行,当用户单击播放按钮时,它将以全屏模式运行。

4

1 回答 1

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:

于 2013-09-16T04:20:13.547 回答