0

我正在将此代码与 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];
}

但是当我播放一个视频,然后导航到另一个视频并尝试播放时,应用程序崩溃了。它给了我这个错误:

http://pastebin.com/nUGLXEAi

4

1 回答 1

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;
}
于 2012-08-22T16:09:48.320 回答