PDA

View Full Version : Movie Player




forrestgrant
Feb 11, 2009, 08:05 AM
I am trying to play videos. I have a table view, if you select the first row, video A plays, if you select the second row, video B plays. This works fine if I open the app, and select a row, however. When I am done with that video, if I then select the next video, nothing happens.

Help?


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

MPMoviePlayerController *player;
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath;

NSInteger row = [indexPath row];
if(row == 0) {
moviePath = [bundle pathForResource:@"video_a" ofType:@"m4v"];
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
} else {
moviePath = [bundle pathForResource:@"video_b" ofType:@"m4v"];
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
}

[player play];
}



jnic
Feb 11, 2009, 08:41 AM
You don't seem to be unloading the player between videos. Try adding a notification for when playback finishes and use it to unload your player:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourMethod:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

- (void)yourMethod:(NSNotification*)notification {
[player release];
}

forrestgrant
Feb 11, 2009, 02:01 PM
Worked. Thanks.
I knew it must be something stupidly simple.