Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

forrestgrant

macrumors member
Original poster
Jun 24, 2008
34
0
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?

Code:
- (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

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
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:

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

Code:
- (void)yourMethod:(NSNotification*)notification {
	[player release];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.