Question

I'm trying to create an NSURL containing a link to an audio file inside my project. I've copied in the audio files (.m4a files) and I'm using this line to fill an NSURL with one of them:

NSURL *fileToBePlayed = [[NSURL alloc] initWithString:[NSString stringWithString:[[NSBundle mainBundle] pathForResource:@"A3" ofType:@"m4a" inDirectory:@"Sounds"]]];

I'm getting the following crash on this line:

2012-06-20 12:32:05.307 TestPlayer[29184:10703] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument'

I'm not sure what the nil argument is about really. The file's definitely there, in the right place, has been copied into the project, etc. I can't see any reason why it wouldn't find the file. If I change the file name to some imaginary file which isn't in there, I get the same crash, so presumably it just can't see the file for some reason. Any ideas?

If I break it out into separate lines, the first two lines here are fine, it's the third one that crashes, the NSURL line:

NSString *testString = [[NSString alloc] init];
testString = [[NSBundle mainBundle] pathForResource:@"A3" ofType:@"m4a"];
NSURL *fileToBePlayed = [[NSURL alloc] initWithString:testString];
Was it helpful?

Solution

Turns out the files hadn't been added to the target, for some reason. Thanks for that, Xcode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top