I created a global variable:
MPMoviePlayerController *player;
I play the video with the following method:
-(IBAction) playMovie: (NSString*) videoName ViedeoType:(NSString*) videoType{
ViewVideoSubview.alpha = 0;
NSString *url = [[NSBundle mainBundle]
pathForResource:videoName
ofType:videoType];
player =
[[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
player.shouldAutoplay =YES;
[ViewVideoSubview addSubview:player.view];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
}
and when the video finishes playing by itself the folloing method get’s called:
- (void) movieFinishedCallback:(NSNotification*) aNotification {
[player.view removeFromSuperview]; //d1
MPMoviePlayerController *playerParam = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerParam];
[player release];
}
Everything works great so far. The problem is that I have a button that when pressed I need to load another view controller. I am able to load that view controller but the video still plays in the background. I don’t why I get an error when releasing the player. my temporary solution is to stop the video then load the other view controller so that the video does not play in the background.
Another solution that I was thinking of is to play the video 1 second before it finishes playing so that it gets released with the method movieFinishedCallback. I don’t know how I will be able to “fast forward” the video to that point. I am new to objective-c and I don’t know what is the aNotification parameter otherwise I will just call that method with the appropriate parameter.
Let me show you the error that I am getting:


I think your problem lies in the way you are trying to remove an observer in the method
movieFinishedCallbackhere you are passing a pointer to your global property player.
and here you are invocing a method to remove observer for all notifications regarding this object
playerParamNow you get an EXEC_BAD_ACCESS because you are sending a pointer (
playerParam) to yourplayer(already released somewhere) to a method (removeObserver) causing an operation ofremoveObserverto be called on an non-existing object.Instead of using
try
Making your object nil will:
More info can be found in NSNotificationCenter Class Reference