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
I have been working on a problem from around 12 hours now and I am stumped. The first bit of code is the MoviePlayerViewController and the second bit is for Audio. The Second bit works when loading the path from an indexPath of a Table yet I cant get the first bit of code to do the same thing by loading from an Array.

I need to convert this bit of code to...

Code:
// Play movie from the bundle
  NSString *path = [[NSBundle mainBundle] pathForResource:@"Movie-1" 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];    
}

This bite of code...

Code:
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];
 
You don't really need to separate the resource from the type; you can pass both in the resource parameter. So this line should work:

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

You can simplify your URL line in the same way.

Code:
NSURL *url = [NSURL fileURLWithPath: 
     [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil]
];

Thats make sense. Using the above the result works out to be...

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

NSURL *url = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:rowTitle ofType:nil]];
		
		// Create custom movie player   
moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:url] autorelease];

Errors says struct NSURL expected NSString.

What about this...

How would one populate (the bold) with an array in any of these examples.

Code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"INFO FROM ARRAY" ofType:@"mp4"];

or

Code:
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"INFO FROM ARRAY"];

I can use the above within an If statement to populate a Cell depending on the indexPath yet the cells are editable and movable so I have a problem when it come to retaining the information for the move. If I have an array populating any of the above I can use an idObject to retain the info per cell.

By changing the NSString *path to NSURL*path seem so never work as the MoviePlayerViewController I have written to handle all SDKs requires NSString.

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