我遇到了问题:我向MPMoviePlayerViewController
添加了detailView
,但是当我点击按钮打开detailView
时,MPMoviePlayerViewController
会自动在FUllScreen模式下播放。现在我想要点击按钮打开DetailView
,MPMoviePlayerViewController
显示播放按钮而不是自动播放。然后用户单击“播放”按钮,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模式运行。
答案 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:
上)