当我在通话期间拔下耳机时,AVAudioEngine崩溃了
这是我在日志中看到的:
16:33:20.236: Call is Dialing 16:33:21.088: AVAudioSessionInterruptionNotification 16:33:21.450: AVAudioSessionRouteChangeNotification 16:33:21.450: ....change reason CategoryChange 16:33:21.539: AVAudioEngineConfigurationChangeNotification 16:33:21.542: Starting Audio Engine 16:33:23.863: AVAudioSessionRouteChangeNotification 16:33:23.863: ....change reason OldDeviceUnavailable 16:33:23.860 ERROR: [0x100a70000] AVAudioIONodeImpl.mm:317: ___ZN13AVAudioIOUnit11GetHWFormatEjPj_block_invoke: required condition is false: hwFormat *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: hwFormat'
我订阅了AVAudioEngineConfigurationChangeNotification
, AVAudioSessionInterruptionNotification
:
@objc private func handleAudioEngineConfigurationChangeNotification(notification: NSNotification) { println2(notification.name) makeEngineConnections() startEngine() } @objc private func handleAudioSessionInterruptionNotification(notification: NSNotification) { println2(notification.name) if let interruptionType = AVAudioSessionInterruptionType(rawValue: notification.userInfo?[AVAudioSessionInterruptionTypeKey] as! UInt) { switch interruptionType { case .Began: audioPlayerNode.stop() case .Ended: if let interruptionOptionValue = notification.userInfo?[AVAudioSessionInterruptionOptionKey] as? UInt { let interruptionOption = AVAudioSessionInterruptionOptions(interruptionOptionValue) if interruptionOption == AVAudioSessionInterruptionOptions.OptionShouldResume { AVAudioSession.sharedInstance().setActive(true, error: nil) startEngine() } } } } } func startEngine() { println2("Starting Audio Engine") var error: NSError? if !audioEngine.running { audioEngine.startAndReturnError(&error) if let error = error { println2("Error initializing Audio Engine: " + error.localizedDescription) } } } private func makeEngineConnections() { let mainMixer = audioEngine.mainMixerNode audioEngine.connect(audioPlayerNode, to: audioEqNode, format: mainMixer.outputFormatForBus(0)) audioEngine.connect(audioEqNode, to: audioTimePitch, format: mainMixer.outputFormatForBus(0)) audioEngine.connect(audioTimePitch, to: mainMixer, format: mainMixer.outputFormatForBus(0)) }
但似乎没有用。
如何避免这次崩溃?
我怀疑问题在这里:
audioEngine.connect(audioTimePitch, to: mainMixer, format: mainMixer.outputFormatForBus(0))
文件说:
此方法调用connect:to:fromBus:toBus:format:使用总线0作为源音频节点,使用总线0作为目标音频节点,除非目标是混音器,在这种情况下目标是混音器的nextAvailableInputBus。
- 如何做NSManagedObject的完美KVO?
- iOS – 无法parsingdatestring“31-07-2014 00:00 BST”使用NSDateFormatter获取string08-31-14
- 带有协议和keyPath()的更安全的Swift应用程序设置
- 在Swift中从AppDelegate获取ViewController的实例
- 当键盘出现时,titanium视图被推高
- Phonegap的iOS 5.1和localStorage
- 如何在Alamofire中使用NetworkReachabilityManager
- Xcode Watchkit:所有有效的configuration文件都不允许指定的权利:beta-reports-active,com.apple.security.application-groups
- XCode 7 – Swift – 通过SFSafariViewController自动加载站点