iOS模拟器无法播放声音

时间:2014-12-12 12:05:37

标签: ios swift xcode6 ios-simulator

在XCode 6上,一切都在设备上运行良好,但在模拟器上,声音不会播放。

我的代码很快:

var url =  NSURL(string: "http://my.url.com/sound.mp3")
var data = NSData(contentsOfURL: url!)
// Removed deprecated use of AVAudioSessionDelegate protocol
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
self.player = AVAudioPlayer(data: data, error: nil)
self.player.prepareToPlay()
self.player.delegate = self
self.player.volume = 1
self.player.play()

有日志:

ERROR:     98: Error '!obj' trying to fetch default input device's sample rate

ERROR:     100: Error getting audio input device sample rate: '!obj'

WARNING:   230: The input device is 0x0; '(null)'

WARNING:   234: The output device is 0x26; 'AppleHDAEngineOutputDP:3,0,1,1:0:{2D4C-092D-00000000}'

ERROR:     400: error '!obj'

ERROR:     113: * * * NULL AQIONode object

ERROR:     180: EXCEPTION thrown ('!dev'): -

ERROR:     703: Can't make UISound Renderer

ERROR:     >aqsrv> 70: Exception caught in (null) - error -1

ERROR:     180: EXCEPTION thrown ('!dev'): -

ERROR:     >aqsrv> 70: Exception caught in (null) - error -1

3 个答案:

答案 0 :(得分:3)

我遇到了这个问题,来自@Matti Jokipii的评论给了我很多帮助。

您需要启用声音输入,因此Mac不会为您提供null异常 转到系统偏好设置>声音。并检查您是否连接了一些输入。如果没有,您将需要添加微缩模型,然后重新运行该应用程序。

enter image description here

答案 1 :(得分:1)

发生错误是因为您试图从模拟器中获取device's sample rate,这是不可能的。

因为模拟器不是硬件。它是一个软件。

因此,某些硬件功能无法用它进行模拟。

无法执行以下操作:

  1. 打开相机
  2. 播放声音
  3. 陀螺测试仪
  4. 加速度计
  5. 摇动效果
  6. 接收推送通知
  7. 还有更多需要设备硬件加速的产品。

    您需要在真实设备中对此进行测试。

答案 2 :(得分:0)

我遇到了这个问题。只需退出,然后再次启动Simulator。

相关问题