AVAudioSession error: Deactivating an audio session that has running I/O

xuyafei picture xuyafei · Feb 24, 2017 · Viewed 13.8k times · Source
2017-02-24 14:56:44.280 PropertyManager[10172:5336578] 14:56:44.280 ERROR:    [0x1a0a24000] AVAudioSession.mm:692: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.

2017-02-24 14:56:44.281 PropertyManager[10172:5336578] error === Error Domain=NSOSStatusErrorDomain Code=560030580 "(null)"
PropertyManager was compiled with optimization - stepping may behave oddly; variables may not be available.

Answer

NSNoob picture NSNoob · Feb 24, 2017

Your error log is very succinctly self-expressive:

Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session

It tells you the problem and also the solution.

Right now you're doing something like this:

[[AVAudioSession sharedInstance] setActive:NO
               withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation
                                             error:nil];

You should however, first stop the audio player instance and then set the activation status to Yes or No.

[yourAudioPlayer stop];
[[AVAudioSession sharedInstance] setActive:NO
                   withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation
                                                 error:nil];

Refer to Apple Documentation to see values of enum AudioSessionSetActiveOption.

Also see: Apple Documentation on setActive:withOptions method

As for your second error

PropertyManager was compiled with optimization - stepping may behave oddly; variables may not be available.

see this excellent answer.