I am using this code with the MediaPlayer framework to play a video:
-(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];
}
But when I play one video, then navigate to another video and try to play it, the app crashes. It gives me this error:
The problem here is you are adding a notification for when the video finishes playing, and that notification triggers a method you do not have (
moviePlayBackDidFinish:) causing the crash.You could implement this method or remove the notification, depends what you want to do after the video is done playing i.e. remove a viewController that plays the video, etc.