0

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);
}
Undo
  • 25,519
  • 37
  • 106
  • 129
Carlos Vela
  • 253
  • 1
  • 12
  • Some audio files only work on the simulator. Does yours follow the correct [guidelines](http://stackoverflow.com/a/4194480/193896)? – bendytree Jun 03 '13 at 18:30

2 Answers2

7

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.

padapa
  • 307
  • 2
  • 12
5

Here's a small detail that many developers have wasted hours upon:

Case Sensitivity

Really, it all boils down to:

  • iPhone Simulator: Case-Insensitive
  • iOS device: Case-Sensitive

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.

Check your Cases!

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

Community
  • 1
  • 1
Undo
  • 25,519
  • 37
  • 106
  • 129
  • i have checked all the specifications of System Sound Services and my sound is no longer than 30 seconds, is packaged in .caf and is linear PCM, i don't know yet why is not playing on my device. Also i have checked the sound name and is waterfall.caf. This sound works perfectly in AVAudio player but not in Systemsound – Carlos Vela Jun 03 '13 at 19:05
  • @CarlosVela Why not use AVAudioPlayer then? – Undo Jun 03 '13 at 19:20
  • I know this is old, but sometimes we tend to miss the most obvious steps. I had the same problem, until I realized that I forgot to add the sound to my target. – KingPolygon Apr 15 '14 at 05:14