AudioServicesPlaySystemSound not playing sounds

我是研究僧i 提交于 2019-12-10 03:21:01

问题


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

AudioServicesPlaySystemSound (soundFileObject);

But sometimes it is not playing.

What is the reason?


回答1:


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.




回答2:


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




回答3:


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?




回答4:


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.




回答5:


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




回答6:


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



来源:https://stackoverflow.com/questions/2720623/audioservicesplaysystemsound-not-playing-sounds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!