I have a navigation based app with a table view and detail view. The detail view contains a UIButton which plays a move. The movie is selected from a key value located in a plist.
This all seems to work fine until I play any given movie more than once. The first run of a movie works fine. The second time around the movie begins to flicker erratically in the simulator and if a movie is played repeatedly back to back the app sometimes freezes or crashes altogether.
Does this sound like a memory issue or is there something else I am missing?
Thank you in advance for your time.
Code:
-(IBAction)playMovieButtonPressed:(id)sender
{
// Path to the movie
NSString *videoSelection = [dvdData valueForKey:@"video"];
NSString *path = [[NSBundle mainBundle] pathForResource:videoSelection ofType:@"m4v"];
NSLog(path);
movieURL = [NSURL fileURLWithPath:path];
// Setup the player
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.movieControlMode = MPMovieControlModeDefault;
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
// Wire up the movieFinishedCallback method
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
// Start the movie
[moviePlayer play];
NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count] > 1)
{
// Locate the movie player window
UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
// Add our overlay view to the movie player's subviews so it is
// displayed above it.
[moviePlayerWindow addSubview:overlay];
}
}
// Callback should be in controller as the playVideo code
-(void)movieFinishedCallback:
(NSNotification*)aNotification
{
MPMoviePlayerController* theMovie = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name: MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
// Release the movie instance
[theMovie stop];
[theMovie autorelease];
NSLog(@"The movie has finished!");
}
- (void)dealloc {
[overlay release];
[movieURL release];
[super dealloc];
}