无论在设备上还是在模拟器中,我似乎都无法播放AudioServices声音。这是我的代码:
NSString *sndPath = [[NSBundle mainBundle] pathForResource:@"click" ofType:@"aiff"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:sndPath], &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesDisposeSystemSoundID(soundID);
我已经检查了系统偏好设置,是的,我确实勾选了“播放用户界面声音效果” ...我可能在做错什么?
谢谢!
编辑:我试图在用户在设备上移动触摸时创建音频点击,所以我需要它来快速播放相同的声音。我应该改用AVAudioPlayer吗?
最佳答案
在声音播放完毕之前,请不要处理声音。您可以执行以下操作:
AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, (AudioServicesSystemSoundCompletionProc)AudioServicesDisposeSystemSoundID, NULL);
由于我们假设它不使用Pascal调用约定(即AudioServicesDisposeSystemSoundID()可以处理额外的NULL参数),因此稍微有点不友好。
关于iphone - 在模拟器或设备上听不到系统声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3469910/