PDA

View Full Version : UITableViewCell - Play Multiple Movie Files from an Array




CeiJay
Jul 17, 2010, 05:16 PM
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.



dejo
Jul 17, 2010, 05:54 PM
I'd suggest scrapping the UIButton and just have the didSelectRowAtIndexPath trigger the movie file to start playing, just like how the iPod and YouTube apps work.

CeiJay
Jul 17, 2010, 06:08 PM
I'd suggest scrapping the UIButton and just have the didSelectRowAtIndexPath trigger the movie file to start playing, just like how the iPod and YouTube apps work.

Thank you for your input - You got my brain thinking. Using what you said and the fact that a Audio and a Video file both need to be played depending on the users requirements. So, what about any of the following options and the process of avenue to achieve them?

1: UIAlertView with Options
2: Double Tap Cell
3: Two Finger Tap Cell
4: Swipe Cell

Thoughts?

dejo
Jul 17, 2010, 06:17 PM
Using what you said and the fact that a Audio and a Video file both need to be played depending on the users requirements.
If you had mentioned that you needed two controls that serve different purposes in your OP, I probably wouldn't have suggested what I did. Now, I'm gonna suggest using two UIButtons in each cell but then having each tagged with the row number so you can use that in the action method to choose the correct file.

CeiJay
Jul 17, 2010, 06:22 PM
If you had mentioned that you needed two controls that serve different purposes in your OP, I probably wouldn't have suggested what I did. Now, I'm gonna suggest using two UIButtons in each cell but then having each tagged with the row number so you can use that in the action method to choose the correct file.

My Apologies. Good idea. Any pointers on having each tagged with the row number. Looking through the Docs...

dejo
Jul 17, 2010, 09:37 PM
My Apologies. Good idea. Any pointers on having each tagged with the row number. Looking through the Docs...
UIView, of which UIButton is a subclass, has a property called, appropriately, tag.

CeiJay
Jul 18, 2010, 06:38 PM
Thank you for your help.

The solution was the following...

NSInteger row = indexPath.row;
NSString *rowTitle = [filmMovie objectAtIndex:row];

NSString *path = [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil];