2015-07-19 8 views
13

Hier ziehen ist, was ich im Protokoll sehen:AVAudioEngine stürzt ab, wenn ich Kopfhörer während eines Gesprächs

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' 

ich beide AVAudioEngineConfigurationChangeNotification, abonniert haben für 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)) 
} 

aber es funktioniert nicht scheinen zu arbeiten.

Wie kann ich diesen Absturz vermeiden?

+0

Gehen Sie zu http://StackOverflow.com/Questions/26728250/avaudioengine-crashes-when-plug-headphones-in--oder- – Omar

+0

Danke, aber das hilft nicht. Wie Sie sehen können, ist die App "AVAudioEngineConfigurationChangeNotification" abonniert. –

+0

Erhalten Sie die Benachrichtigungen? Wird der Ton erfolgreich gestoppt? oder stürzt es ab, bevor die Benachrichtigung empfangen wird. – Omar

Antwort

1

Ich vermute, das Problem hier ist:
audioEngine.connect(audioTimePitch, to: mainMixer, format: mainMixer.outputFormatForBus(0))

Die documentation sagt:

Diese Methode Anrufe verbinden: zu: fromBus: tobus: Format: mit Bus 0 für den Audioquellknoten, und Bus 0 für den Ziel-Audioknoten, außer im Falle eines Ziels, bei dem es sich um einen Mischer handelt, wobei in diesem Fall das Ziel der NextAvailableInputBus des Mischers ist.