How do I gain access to a crashSound.wav file I’ve put in my Supporting Files folder of my xCode Project? Because the following code isn’t working :
@interface Game()
{
// code...
AVAudioPlayer *crashSound;
// code...
}
@end
@implementation Game
- (id) init
{
// code...
NSURL *crashSoundFile = [[NSURL alloc] initWithString:@"crashSound" ]; // <--PROBLEM
crashSound = [[AVAudioPlayer alloc] initWithContentsOfURL:crashSoundFile error:NULL];
// code...
}
-(void) play // this is my "main" method that will be called once the playButton is pressed
{
[crashSound play];[crashSound play];[crashSound play];
}
@end
@"crashSound"is not a valid URL. You must supply an actual URL.URLs to images, sounds, etc. (resources) in your project are not predictable at compile-time, and must be generated at run-time. This is easy using
NSBundle.Ta da.