我在MediaPlayer框架中使用此代码来播放视频:
-(void)GrommeVideoExcerpt1
{
NSURL *url1 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"GrommeVideoExcerpt1" ofType:@"mp4"]];
grommePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:url1];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:grommePlayer1];
grommePlayer1.controlStyle = MPMovieControlStyleDefault;
grommePlayer1.shouldAutoplay = YES;
[self.view addSubview:grommePlayer1.view];
[grommePlayer1 setFullscreen:YES animated:YES];
}
但是,当我播放一个视频,然后导航到另一个视频并尝试播放时,该应用程序崩溃了。它给了我这个错误:
答案 0 :(得分:0)
此处的问题是您要在视频播放完毕时添加通知,并且该通知会触发您没有的方法(moviePlayBackDidFinish:
)导致崩溃。
您可以实现此方法或删除通知,取决于您在完成视频播放后要执行的操作,即删除播放视频的viewController等。
//Register notification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
//Then the method ...
-(void) moviePlaybackDidFinish:(NSNotification *)aNotification{
[grommePlayer1.view removeFromSuperview];
grommePlayer1 = nil;
}