2014-11-04 91 views
2

我正在測試我的audioApp在我的耳機上iPhone6 Plus,並且在插入耳機或插入耳機後發生崩潰。 AVAudioEngine,AVAudioMixer,AVAudioPlayerNode用於我的應用程序。AVAudioEngine在插入耳機或插入耳機時崩潰

沒有耳機的應用程序可以從iPhone揚聲器播放聲音。

用耳機啓動應用程序可以從耳機播放聲音。

以下情況會發生錯誤。 在沒有耳機的情況下啓動應用程序並播放揚聲器中的聲音。然後,如果我連接耳機,則耳機沒有聲音。當我拔掉耳機後,即使是揚聲器也沒有聲音。當我觸摸屏幕時audioApp會崩潰。

與用耳機啓動應用程序並將耳機插入相同。

我該如何解決這個錯誤? 我很感激你的建議。

這是我收到的錯誤消息。

Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning()' 
*** First throw call stack: 
(0x184d61e48 0x1954a80e4 0x184d61d08 0x1836d26c0 0x1836fa328 0x1836f975c 0x1000d03c0 0x1000d0728 0x1895450f8 0x18952e22c 0x189544a94 0x189544720 0x18953dc74 0x18951138c 0x1897b01b4 0x18950f8f4 0x184d1a0e8 0x184d1938c 0x184d1743c 0x184c451f4 0x18ddd35a4 0x189576784 0x1000d5614 0x1000d5654 0x195b16a08) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

回答

3

您需要註冊的AVAudioEngineConfigurationChangeNotification通知,並做必要的步驟來更新輸出節點。

+1

工作,謝謝!我也使用[這個鏈接](http://stackoverflow.com/questions/24126261/swift-alternative-to-performselectoronmainthread)如何改變標籤文本,而開/關耳機。 – 2014-11-18 09:39:45

+2

那麼更新輸出節點的必要步驟是什麼?我正在使用mainMixer節點,根本不使用引擎的輸出節點。但是,當我插入耳機時,引擎無法啓動。 – 2015-03-13 11:20:48

+1

如果您剛插入一個新的輸出節點,則需要將其連接到mainMixer節點。 – Allen 2015-03-14 02:09:53