Kev*_*OUX 5 ios ios-simulator swift xcode6
在 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()
Run Code Online (Sandbox Code Playgroud)
有日志:
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
Run Code Online (Sandbox Code Playgroud)
我遇到了这个问题, @Matti Jokipii的评论对我帮助很大。
您需要启用声音输入,这样您的 Mac 就不会出现 null 异常。
转至系统偏好设置 > 声音。并检查您是否已连接一些输入。如果没有,您将必须添加麦克风,然后重新运行应用程序。
发生错误是因为您试图device's sample rate从模拟器中获取,这是不可能的。
因此某些硬件功能将无法用它来模拟。
它不能执行以下操作:
还有更多需要设备硬件加速的。
您需要在真实设备中对此进行测试。
| 归档时间: |
|
| 查看次数: |
7107 次 |
| 最近记录: |