Helpful Information
 
 
Category: iPhone SDK Development
UITableViewCell - Play Multiple Movie Files from an Array

Hello All

iOS4 - iPhone 4 & 3GS

I have a Table based application using Custom UITableViewCell's. The custom Cell has a UIButton within it for playing a movie file. At the moment I have Arrays to populate the information within each cell depending on the Indexpath. All information within the Cell is placed within cellForRowAtIndexPath and all actions are within didSelectRowAtIndexPath.

The UIButton within each cell plays a movie using the standard MoviePlayerViewController like so (other code not shown)


- (void)loadMoviePlayer

{

// Play movie from the bundle NSString *path = [[NSBundle mainBundle] pathForResource:@"Mov2" ofType:@"mp4" inDirectory:nil];

// Create custom movie player
moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:path] autorelease];

// Show the movie player as modal [self presentModalViewController:moviePlayer animated:YES];

// Prep and play the movie [moviePlayer readyPlayer];
}

The UIButton within the CustomCell is linked to the following:


-(IBAction)playMovie {

[self loadMoviePlayer];
}

Here is an example of Audio being played within didSelectRowAtIndexPath. A Array controllers the stringWithFormat using the TabelView IndexPath. Each Cell plays a certain file...


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

NSUInteger row = [indexPath row]; NSString *rowTitle = [filmSound objectAtIndex:row];

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], rowTitle]]; NSError *error; AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];

if (player != nil) { [self setTheAudio: player]; [player release], player = nil;

[self.theAudio setDelegate:self];

[self.theAudio play]; }

[tableView deselectRowAtIndexPath:indexPath animated:YES]; }

I need to be able to do the same the the movie file actioned by the UIButton in the CustomCell. The - (void)loadMoviePlayer code will not work as an Indexpath is not defined. Have it in didSelectRowAtIndexPath still will not allow me to get the Array working.

Options in my brain right now... 1. Change the - (void)loadMoviePlayer to include the indexPath as a ref and change the pathForResource to handle the Array. 2. Change the - (void)loadMoviePlayer to include the indexPath as a ref and use an if / else statement will blocks of the MoviePlayer code to repeat the process using (indexPath.row % 2 == 0)

Recap... UITableView with CustomCell using Array to populate cell information and didSelectRowAtIndexPath need MoviePlayer which is attached to a UIButton within the CustomCell to be played depending on the IndexPath / Cell.

Your help would be gratefully appreciated. Any question please feel free to ask. Thank you in advance.










privacy (GDPR)