objective-c 声音在 iPhone 模拟器中不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/302399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sound not working in iPhone Simulator?
提问by pix0r
Somehow my iPhone Simulator is unable to play sounds. First an app I'm working on using AudioServicesPlaySystemSound()stopped working.. I spent a while debugging this but sound is still working on the iPhone when I run the app on the device. I get the same results with other iPhone apps such as the sample Crash Landing app.
不知何故,我的 iPhone 模拟器无法播放声音。首先,我正在使用的一个应用程序AudioServicesPlaySystemSound()停止工作。我花了一段时间调试它,但当我在设备上运行该应用程序时,声音仍在 iPhone 上工作。我在其他 iPhone 应用程序(例如示例 Crash Landing 应用程序)上得到了相同的结果。
I can't find a sound setting anywhere in the simulator or Xcode preferences. I've tried resetting the simulator through "Reset Content and Settings" menu item to no avail.
我在模拟器或 Xcode 首选项中的任何地方都找不到声音设置。我尝试通过“重置内容和设置”菜单项重置模拟器无济于事。
回答by
回答by auco
I had no sound in the simulator, so I tested it with mobile safari and tried playing an mp3: No sound!
我在模拟器中没有声音,所以我用 mobile safari 测试它并尝试播放 mp3:没有声音!
All the above tips didn't help. Eventually, I changed my INPUTsource from the virtual soundflower device to Line-In, and the Simulator worked!
以上所有提示都没有帮助。最终,我将INPUT源从虚拟 soundflower 设备更改为 Line-In,并且模拟器工作了!
So, even if the app wasn't using input, it didn't work well with Soundflower.
因此,即使应用程序没有使用输入,它也不能很好地与 Soundflower 配合使用。
回答by Xie Wei
I've seen this problem after my update from OSX10.5.7 to 10.6.2
我从 OSX10.5.7 更新到 10.6.2 后看到了这个问题
And I made the following changes to make the simulater sing again: Goto "Applications/Utilities" and run "Audio MIDI Setup", then change midi format from 48000 to 44100.
我进行了以下更改以使模拟器再次唱歌:转到“应用程序/实用程序”并运行“音频 MIDI 设置”,然后将 MIDI 格式从 48000 更改为 44100。
回答by Marc Novakowski
I've found sound to be very inconsistent in the simulator (2.1 SDK). Sometimes it works, sometimes it doesn't. Even when it does work, it's usually very choppy and distorted (when playing audio files such as mp3).
我发现模拟器(2.1 SDK)中的声音非常不一致。有时它有效,有时它不起作用。即使它确实有效,它通常也非常断断续续和失真(在播放 mp3 等音频文件时)。
A few things to remember:
要记住的几件事:
- call
AudioSessionInitializeas soon as your app finishes launching - set the
kAudioSessionProperty_AudioCategoryproperty for the session viaAudioSessionSetProperty(with a value such askAudioSessionCategory_MediaPlayback) - call
AudioSessionSetActive(YES)
AudioSessionInitialize您的应用程序完成启动后立即调用- 通过设置
kAudioSessionProperty_AudioCategory会话的属性AudioSessionSetProperty(使用诸如 之类的值kAudioSessionCategory_MediaPlayback) - 称呼
AudioSessionSetActive(YES)
Of course when all else fails, just run it on your hardware!
当然,当所有其他方法都失败时,只需在您的硬件上运行它!
EDIT: Now that the 2.2 SDK has been released, I haven't had any problems with sound in the simulator. They must have fixed the bugs! I highly recommend you upgrade to the 2.2 SDK.
编辑:现在 2.2 SDK 已经发布,我在模拟器中没有任何声音问题。他们一定已经修复了错误!我强烈建议您升级到 2.2 SDK。
回答by Steph Thirion
OpenAL not working on the simulator was fixed with the 2.1 SDK. Make sure Active SDK andActive Executable are set to 2.1.
OpenAL 无法在模拟器上运行已通过 2.1 SDK 修复。确保 Active SDK和Active Executable 设置为 2.1。
By the way, make sure you're using the last version of CrashLanding (v1.8). Some nasty leaks in SoundEngine were fixed recently.
顺便说一句,请确保您使用的是最新版本的 CrashLanding (v1.8)。SoundEngine 中的一些令人讨厌的泄漏最近已得到修复。
回答by kritzikratzi
if reactivating system sounds didn't work for you try this: launch audio-midi-setup, then configure your "built in output" to use 44.100Hz, 2 channels, 24 bits. (from http://www.cocos2d-iphone.org/forum/topic/4159)
如果重新激活系统声音对您不起作用,请尝试以下操作:启动 audio-midi-setup,然后将您的“内置输出”配置为使用 44.100Hz、2 通道、24 位。(来自http://www.cocos2d-iphone.org/forum/topic/4159)
somehow after a few days, my iphone simulator now wants 48.000Hz, 2 channels, 24 bits. just play with it for a bit and be warned that it might change randomly when plugging in headphones, going to standby, restarting, etc.
几天后不知何故,我的 iphone 模拟器现在需要 48.000Hz、2 个通道、24 位。只需玩一会儿,并注意它可能会在插入耳机、待机、重新启动等时随机变化。
and here's a an off-topic hint: when you plug headphones into your iphone/ipad the buffer size might double (e.g. from 512bytes to 1024 bytes), make sure you don't rely on the buffersize you requested!
这是一个题外话的提示:当您将耳机插入 iphone/ipad 时,缓冲区大小可能会加倍(例如从 512 字节到 1024 字节),请确保您不依赖于您请求的缓冲区大小!

