AudioServicesPlaySystemSound not playing sounds

后端 未结 6 1883
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 14:44

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

AudioServicesPlaySystemSound (soundFileObject);

But sometimes it is not playing.

相关标签:
6条回答
  • 2021-02-20 15:11

    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?

    0 讨论(0)
  • 2021-02-20 15:13

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

    0 讨论(0)
  • 2021-02-20 15:21

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

    0 讨论(0)
  • 2021-02-20 15:21

    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

    0 讨论(0)
  • 2021-02-20 15:24

    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.

    0 讨论(0)
  • 2021-02-20 15:31

    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.

    0 讨论(0)
提交回复
热议问题