MPMoviePlayerController not released
I am running an intro movie in a MPMoviePlayerController and i've got a problem with the allocated memory not being released.
When the movie finishes, Instruments shows the memory being released. However when i skip the movie by tapping on it the memory is not released. Here are the important parts of my code:- (void)applicationDidFinishLaunching:(UIApplication *)theApplication {
self.application = theApplication;
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"mymovie.mov" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[window addSubview:moviePlayer.view];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.frame = window.frame;
UIView *introFrontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
introFrontView.userInteractionEnabled = YES;
introFrontView.opaque = NO;
introTabRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(introTabFrom:)];
[introFrontView addGestureRecognizer:introTabRecognizer];
[moviePlayer.view addSubvie开发者_如何学Gow:introFrontView];
[introFrontView release];
[introTabRecognizer release];
self.moviePlayerController = moviePlayer;
[moviePlayer release];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(introFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
[self.moviePlayerController play];
}
- (void)introTabFrom:(UITapGestureRecognizer*)recognizer{
[[NSNotificationCenter defaultCenter] postNotificationName:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
}
- (void) introFinished:(NSNotification*)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
[self.moviePlayerController pause];
[self.moviePlayerController stop];
[self.moviePlayerController release];
...
}
Is there anything i forgot?
To my understanding i'm posting the correct notification... Any ideas?You may want to register for MPMoviePlayerPlaybackStateDidChangeNotification, and look at the playbackState that is passed in.
精彩评论