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
How would one use this Array...

Code:
if (filmMovie == nil)
    {
        NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
                                 @"Mov1.mp4", 
								 @"Mov2.mp4", 
								 @"Mov1.mp4", 
								 @"Mov2.mp4", 
								 @"Mov1.mp4", 
								 @"Mov2.mp4", 
                                 @"Mov1.mp4", 
								 @"Mov2.mp4", 
								 @"Mov1.mp4", 
								 @"Mov2.mp4", nil];
        self.filmMovie = array;
        [array release];        
    }

to populate this...

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

or

Code:
NSString *path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"INFO FROM ARRAY"];
 
Are you trying to figure out how to reference a single element/object from the array using, say, an index number?

Hi Again Dejo

I managed to get the following to load an audio file from an Array without a problem.

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];

yet with this...

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

or this...

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

I am unable to do the exact same thing. Using the Audio example does not work as NSString*path is required.
 
Show real code. The literal string @"INFO FROM ARRAY" can't possibly work.

Also, pathForResource expects resource names to NOT have an extension if the ofType parameter is non-nil. Your array of strings DOES have ".mp4" extensions on every string. So either remove the extensions from the array strings, or pass nil instead of "mp4". Refer to the NSBundle reference doc, in the section on pathForResource methods.
 
Show real code. The literal string @"INFO FROM ARRAY" can't possibly work.

Also, pathForResource expects resource names to NOT have an extension if the ofType parameter is non-nil. Your array of strings DOES have ".mp4" extensions on every string. So either remove the extensions from the array strings, or pass nil instead of "mp4". Refer to the NSBundle reference doc, in the section on pathForResource methods.

Hi Chown

Thank you for your input. I am happy with the inType and removing from the Array and the Nil pass. Refined Question.

NSString *path = [[NSBundle mainBundle] pathForResource:mad:"%@" ofType:mad:"mp4"];

%@ need to be whatever is in the Array. One example that seems not to work because it changes NSString *path to NSURL *path.

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

--

How to load info from the Array into here... making sure to keep using NSString *path =

NSString *path = [[NSBundle mainBundle] pathForResource:mad:"%@" ofType:mad:"mp4"];

Thoughts?
 
NSString *path = [[NSBundle mainBundle] pathForResource:mad:"%@" ofType:mad:"mp4"];

%@ need to be whatever is in the Array. One example that seems not to work because it changes NSString *path to NSURL *path.

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

--

How to load info from the Array into here... making sure to keep using NSString *path =

NSString *path = [[NSBundle mainBundle] pathForResource:mad:"%@" ofType:mad:"mp4"];

Thoughts?
If that's your actual code, it can't possibly work. You can't just throw in a formatting string @"%@" for any method. Only a small number of methods accept formatting strings. pathForResource is not one of them.

You've already posted code that retrieves an indexed string from the array. It's this:
Code:
NSUInteger row = [indexPath row];
    NSString *rowTitle = [filmSound objectAtIndex:row];
If you can't figure out how to proceed, then you should think about what's in the string rowTitle, and how that relates to the pathForResource string. If it's still not clear, you need to go back and review the basics.

You should also take a little time and mentally step through what value is in each variable. Use a pencil and paper if you can't keep it all in your head. If you don't understand what values are in which variables, and how those values relate to what you're trying to do, you can't possibly write code effectively. You need to think it through and understand the code.
 
Thank you for all you help Chown - I will work on it...
 
If that's your actual code, it can't possibly work. You can't just throw in a formatting string @"%@" for any method. Only a small number of methods accept formatting strings. pathForResource is not one of them.

You've already posted code that retrieves an indexed string from the array. It's this:
Code:
NSUInteger row = [indexPath row];
    NSString *rowTitle = [filmSound objectAtIndex:row];
If you can't figure out how to proceed, then you should think about what's in the string rowTitle, and how that relates to the pathForResource string. If it's still not clear, you need to go back and review the basics.

You should also take a little time and mentally step through what value is in each variable. Use a pencil and paper if you can't keep it all in your head. If you don't understand what values are in which variables, and how those values relate to what you're trying to do, you can't possibly write code effectively. You need to think it through and understand the code.

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.