如何停止在MoviePlaybackDidFinish MPMoviePlayerViewController的自动closures?

通过presentMoviePlayerViewControllerAnimated:模态方式呈现的MPMoviePlayerViewController presentMoviePlayerViewControllerAnimated:在内容完成播放时自动解散。

我试图禁用这个,因为我想以后播放其他内容。 但是,即使我使用[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer];注册到NSNotificationCenter [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer]; 并设置了一些其他的内容,它仍然驳回。

我怎样才能阻止MPMoviePlayerViewController自动解散?

更新:

作为一个澄清,这个问题只是关于消除自动解雇,而不是处理残疾人“完成”button。 所选答案反映。 这是devise的,因为我们假设开发人员添加他们自己的解雇MPMoviePlayerViewController的手段。 不过, @ bickster的回答也是处理“完成”button。

感谢这篇博客文章,我发现MPMoviePlayerViewController在创build时会自动注册到NSNotificationCenter。 你必须先删除这个注册,它将自动停止解散。

 // Initialize the movie player view controller with a video URL string MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease]; // Remove the movie player view controller from the "playback did finish" notification observers [[NSNotificationCenter defaultCenter] removeObserver:playerVC name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer]; 

当用户单击“完成”button时,您可以使用此代码停止视图控制器自动closures和捕获事件,以便您可以自行closures视图控制器。

第1步 – 分配一个MPMoviePlayerViewController

 videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[[NSURL alloc ]initWithString:[aURL]; 

第2步 – 删除默认的MPMoviePlayerPlaybackDidFinishNotification观察者,并添加自己的

 [[NSNotificationCenter defaultCenter] removeObserver:videoPlayer name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer]; 

第3步 – 现在的viewcontroler

 [self presentMoviePlayerViewControllerAnimated:videoPlayer]; 

第4步 – 添加videoFinish:方法

 -(void)videoFinished:(NSNotification*)aNotification{ int value = [[aNotification.userInfo valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue]; if (value == MPMovieFinishReasonUserExited) { [self dismissMoviePlayerViewControllerAnimated]; } } 

你可以尝试这样的事情。

当mpmovieplayercontroller完成播放video,并在您的方法movieFinishedCallback中收到通知实现

  [playerVC.movieplayer setContentURL:// set the url of the file you want to play here]; [playerVC.moviePlayer play]; 

希望这可以帮助

由于“完成”button不工作了,如果我从NSNotificationCenter删除MPMoviePlayerPlaybackDidFinishNotification ,我改变重复模式为MPMovieRepeatModeOne 。 然后,除了重复的video,一切正常。

 MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease]; [playerVC.moviePlayer setRepeatMode:MPMovieRepeatModeOne];