iphone - 在模拟器或设备上听不到系统声音

标签 iphone ipad audio ios-simulator

无论在设备上还是在模拟器中,我似乎都无法播放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/

相关文章:

ios - Firebase iOS 卡在 'Run your app to verify installation'

iphone - 目前 Siri 开放 API 可用吗?

iphone - 从 subview 使用 presentModalViewController

scala - Scala-播放声音-蜂鸣

iphone - 有没有办法查明 iPhone 是否通过 A-GPS、手机信号塔信号强度或 wifi 获得了 CLLocation?

iphone - 在不使用 XIB 本地化的情况下本地化我的 iPhone 应用程序?

iphone - 通用应用程序中的 Icon.png 文件错误

iphone - 获取任何 iOS 应用程序的完整自定义 URL 方案和路径

audio - 创建自定义声音识别软件以切换音频的建议

ios - 防止 AVPlayer 取消背景音频