Xcode模拟器中无法播放音频文件的原因分析

在本猫的Mac Mini上开发iOS app,发现当执行到播放音频的代码时,发生错误,log如下:

2015-10-05 07:22:17.122 LearnSpriteBuilder[10321:559370] 07:22:17.122 ERROR:     98: Error '!obj' trying to fetch default input device's sample rate
2015-10-05 07:22:17.122 LearnSpriteBuilder[10321:559370] 07:22:17.122 ERROR:     100: Error getting audio input device sample rate: '!obj'

看了一下,貌似是和音频输入设备有关,可是我是播放音乐,并没有录音啊,按道理只用到音频输出设备,不用输入设备吧?

然而同样的代码在MacAir和真机上都运行正常,声音播放的杠杠的.

于是到Stack Overflow搜索,发现2个比较靠谱的答案:

The error occurs because you are trying to get device's sample rate from simulator, which is not possible.

Because simulator is not a hardware. Its a software.

So some hardware functionality will not able to simulated with it.

It can not do the following:

Open Camera
Play sounds
Gyrometer
Accelerometer
Shake effect
And many more which required device hardware acceleration.

You need to test this in real device.

这哥们说模拟器是软件而不是硬件,无法播放音频,必须到真机上测试.
但是在macAir的模拟器上是可以播放的,所以问题不在这.

另一哥们说:

I was having this problem, the comment from @Matti Jokipii, helped me a lot.

You need to have a sound input enabled, so your Mac doesn't give you the null exception.
Go To System Preferences > Sound. And Check you have some input connected. If not, you will have to add a microfone, and re-rerun the app.

这里写图片描述

Ta说到系统设置的Sound中去看其中的Input栏中是否有设备,如果有那么可以播放,否则你必须添加一个输入设备才可播放.如果我没记错的话,MacAir是有输入设备的(可以录音),而Mac mini貌似没有.网上还有人说在mini上插个耳机就可以了,这应该是因为耳机上带有输入的话筒,不信可以到Input栏中看一下.但是没有输入话筒的耳机插上去也是不行的,我记得iPhone的耳机是带输入话筒的,而iPod shuffle耳机是没有的.

等回去再验证下.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值