Reputation: 253
I want to play a system sound on my iphone, the sound plays very well in the simulator but on the device doesn't work.
- (IBAction)SystemSound:(id)sender {
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"waterfall" ofType:@"caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundFileURL, &systemSound);
AudioServicesPlaySystemSound(systemSound);
}
Upvotes: 0
Views: 1878
Reputation: 307
Couple other things to check before chasing the code issues listed above:
1) Is your phone paired with a Bluetooth headset? If so, the audio will come out there instead of your external speaker.
2) Is your audio muted? Check the switch on the side and your settings.
Upvotes: 7
Reputation: 25697
Here's a small detail that many developers have wasted hours upon:
Really, it all boils down to:
So, you might have 'waterfall' in your code, but the actual sound name is 'Waterfall'. It might even be something like 'wAtErFaLl'.
This will work fine on the simulator, but not on the device - the device simply won't find the sound.
This has happened to me for everything from sounds to images to plists.
Also, AudioServices has some guidelines on what can play in the device and what can't:
Sound files that you play using this function must be: - No longer than 30 seconds in duration - In linear PCM or IMA4 (IMA/ADPCM) format - Packaged in a .caf, .aif, or .wav file
Upvotes: 5