Loading a Soundfont file in objective C SpriteKit project

157 views Asked by At

The app I am creating is for Mac OS X using SpriteKit, although this probably doesn't make much of a difference. I am trying to load a Soundfont file, but it is not loading and I'm not sure what I'm doing wrong. The Soundfont file is called "Grand Piano.sf2" and it is located in the main bundle of the project. How can I get it to load properly?

Here's my code:

NSString *filename = @"Grand Piano";
NSURL *piano = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:filename ofType:@"sf2"]];

This is the error I receive:

***-[NSURL initFileURLWithPath:]: nil string parameter
1

There are 1 answers

0
Whirlwind On BEST ANSWER

This is happening because pathForResource: ofType: has returned nil , which means that file could not be located...

If you are sure that there is a file with that name located in your main bundle , then I would check under "Build Phases" -> "Copy Bundle Resources" to see if "Grand Piano.sf2" is present. If it isn't, use the + button (add items will show up when hover) and add it.

Hope this helps.