我正在使用通知中心接收MPMoviePlayerPlaybackDidFinishNotification,它按预期工作。
NSURL * url = [[NSURL alloc] initWithString:@"http://INFINITECREATIVEUNIVERSE.COM/Media/module_1_Dec/c_January27AffactPerfect.mov"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer.view setFrame:CGRectMake(0, 0, 500, 260)];
[self.view addSubview:moviePlayer.view];
//Some addiontal customization
moviePlayer.fullscreen = YES;
moviePlayer.allowsAirPlay = YES;
moviePlayer.shouldAutoplay = YES;
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
//moviePlayer.endPlaybackTime = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playMovieFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
选择器按照我的意愿行事。
-(void)playMovieFinished:(NSNotification*)theNotification
{
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
// Change Segue ID Here
[self performSegueWithIdentifier:@"VC_5" sender:self];
}
当视频仍在播放时,如果我点击下一个按钮,则会出现问题。当我的下一个ViewController出现时,没有视频,我仍然可以听到前一个ViewController的音频。
我的问题是: 如何正确关闭View Controller和MPMoviePlayer。 我搞不清楚了。 我从Apple下载了示例MoviePlayer项目,但它现已弃用,但无法正常运行。 我迷失了如何使这项工作。 我正在交叉手指,我正确地问了这个问题。请怜悯我的新手问题。谢谢你罗伯特
答案 0 :(得分:0)
使用此代码
-(void)playMovieFinished:(NSNotification*)theNotification
{
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer stop];
// Change Segue ID Here
[self performSegueWithIdentifier:@"VC_5" sender:self];
}