iOS模拟器不播放声音

标签 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

最佳答案

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

您需要启用声音输入,这样您的 Mac 才不会给您 null 异常。
转到系统偏好设置 > 声音。并检查您是否连接了一些输入。如果没有,您将必须添加一个麦克风,然后重新运行该应用。

enter image description here

关于iOS模拟器不播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27443311/

相关文章:

ios - TestFlight 是否支持 ios7 及更早版本?

objective-c - 如何解决 EXC_BAD_ACCESS (SIGSEGV) 上的 KERN_INVALID_ADDRESS

java - libGDX : desgin game assets according different size screens

ios - 进度 View 无限步?

ios - 打开 Storyboard文件时出错

ios - 收到错误 "ReactiveCocoa/ReactiveCocoa.h"找不到文件

iphone - iPhone 终端用户更新应用程序需要多长时间?

string - 在 Swift 中将数字与字符串连接起来

ios - 无法将解析的数据保存到 URLSession 到 Core Data 上下文(iOS 10、Swift 3)

swift - 未保存核心数据关系数据