12

I am playing a small .wav file using the AudioToolBox.

AudioServicesPlaySystemSound (soundFileObject);

But sometimes it is not playing.

What is the reason?

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
Biranchi
  • 16,120
  • 23
  • 124
  • 161

6 Answers6

16

If you're in the Simulator, make sure that in System Prefrences → Sound, that "Play user interface sound effects" is not turned off. If you're on the device, check that the ringer switch is not set to silent.

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
lucius
  • 8,665
  • 3
  • 34
  • 41
  • I can't find any "System Preferences". Are they in the simulated device or in the simulator application? – Roger C S Wernersson Jan 09 '12 at 00:03
  • I mean on Mac OS X, in your computer's System Preferences. – lucius Jan 31 '12 at 22:52
  • Holy cow, that's dumb. What kind of a "simulation" mirrors the settings of its host system like this? – jscs Sep 27 '13 at 23:36
  • Another big "thanks" here; agreed, @Josh. Note, too, that this setting seems to affect only AudioServices (and maybe only AudioServicesPlaySystemSound); sounds played with the AVAudioPlayer are not affected. – big_m Oct 30 '13 at 22:16
  • NOTE: Even with headphones in the sound will not play if the phones silent switch is on, Just lost 2 hours to this. – Joe Maher Apr 13 '15 at 06:44
6

Maybe it's this issue? AudioServicesDisposeSystemSoundID() will stop the sound work before playing.

Community
  • 1
  • 1
3

Building on user1056521's answer, use the following code:

AudioServicesPlaySystemSoundWithCompletion(soundID, ^{
    AudioServicesDisposeSystemSoundID(soundID);
});

where soundID is the SystemSoundID value you got when you called AudioServicesCreateSystemSoundID().

The completion block ensures the sound was played and completed playing before it is disposed of.

Ameer Sheikh
  • 770
  • 5
  • 14
2

System Preferences → Sound → [x] Play user interface sound — this checkbox helped for me too, it solved the AudioServicesPlaySystemSound(_) issue. But worth noting was that the sample Apple Xcode project "SysSound" worked just fine without checking this box. I'm using the Xcode 4.4.1 for creating own app from scratch. Could there be differencies between projects created with older and newer Xcode tools?

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
rbki
  • 21
  • 1
  • The SysSound example works for the AudioServicesPlayAlertSound button but not for the AudioServicesPlaySystemSound button. Even though they're the same sound. – samkass Oct 07 '12 at 04:03
1

For those who visit this question later,

AudioServicesPlaySystemSoundID()'s volume is based on system Ringer in range of 0.1 ~ 1.0, not mediaVolume

AudioServicesPlayAlertSoundID()'s volume is based on system Ringer in range of approximately 0.3 ~ 1.0

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
0

On the device, go into settings and turn up the volume on Sounds->Ringer and Alerts

northernman
  • 1,446
  • 16
  • 19