Reputation: 11951
I am trying to play a sound in my app with the following code:
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"errorbeep.wav" ofType:@"m4a"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL
error:nil];
player.numberOfLoops = -1; //Infinite
[player play];
But the sound does not play :(
after debugging, I can see that soundFilePath is nil Here is a screenshot of my Resources file:
Upvotes: 0
Views: 261
Reputation: 367
Select your sound file and see if you have its Target Membership Checked for your target.
Upvotes: 0
Reputation: 244
You should import the file to your project with one extension. Thats probably what's going on. Just re-import the file as one extension (i.e, errorbeep.m4a)
Upvotes: 1
Reputation: 3099
If the file path is nil I would try renaming the file to just errorbeep.m4a and then doing:
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"errorbeep" ofType:@"m4a"];
Upvotes: 0