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

CeiJay

macrumors newbie
Original poster
Jul 17, 2010
15
0
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)

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

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

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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

macrumors newbie
Original poster
Jul 17, 2010
15
0
Options

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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

macrumors newbie
Original poster
Jul 17, 2010
15
0
Almost There

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...
 

CeiJay

macrumors newbie
Original poster
Jul 17, 2010
15
0
Thank you for your help.

The solution was the following...

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

		NSString *path = [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.