Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k 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 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...