Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
956 views
in Technique[技术] by (71.8m points)

swift - AVAudioEngine crashes when plug headphones in or out

I'm testing my audioApp on my iPhone6 Plus, and it crashes after plug headphone in or out. AVAudioEngine, AVAudioMixer, AVAudioPlayerNode is used in my app.

starting app without headphone can play sound from iPhone speaker.

starting app with headphone can play sound from headphone.

The error occurs in following condition. starting app without headphone and play sound from speaker. Then if I connect headphone there is no sound coming from headphone. when I unplug my headphone after that, there is still no sound coming even from speaker. and audioApp crashes when I touch the screen.

the same as starting app with headphone and plug my headphone out.

How can I fix this error? I'd appreciate your advice.

here is the error message I got.

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to register to the AVAudioEngineConfigurationChangeNotification notification and do the necessary steps to update the output node.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...