13
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.
NSNoob
  • 5,548
  • 6
  • 41
  • 54
xuyafei
  • 139
  • 1
  • 1
  • 4

3 Answers3

20

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.

Community
  • 1
  • 1
NSNoob
  • 5,548
  • 6
  • 41
  • 54
  • 1
    [yourAudioPlayer stop] should be [yourAudioPlayer pause]. – The iCoder Feb 22 '18 at 06:13
  • @TheiCoder Hmm why? It can be either of those, depending on the OP's needs. – NSNoob Feb 22 '18 at 07:38
  • 2
    I still get the error even after making sure the player has paused. I've even made it nil before trying to deactivate the session, but nothing has changed. – Jargen89 Nov 06 '18 at 20:54
  • @Jargen89 Put a breakpoint when you pause it, then inspect the element when you hit session deactivation. See if it is really paused or if some other line of code is making it resume. – NSNoob Nov 07 '18 at 05:55
  • 1
    @NSNoob, it's working now, but only after starting my machine and iphone back up the next morning. Thanks. – Jargen89 Nov 07 '18 at 14:14
  • @ NSNoob could you also check this? tnx https://stackoverflow.com/questions/55910290/avaudiosession-plays-sound-on-receiver-or-mic-dont-tap – Spring May 02 '19 at 20:25
  • @NSNoob , is this still working from your end, pls testing this solution is giving same error on iOS 12+ . I will like to know if there is anything i can do as regards this, pls. – Israel Meshileya May 07 '19 at 12:56
  • I still get the error even after pausing the player on iOS 14. So I called setActive: false method with a delay of 0.1 seconds after pausing my player, and there is no error log is printed. – manman Mar 04 '21 at 07:46
1

@NSNoob is 100% correct. The player (or something else) is still active.

More from dani-mp. He said:

I'd say that pausing the player is not a synchronous operation, so we shouldn't be deactivating the session before knowing that the player has been paused (see the response in this thread).

A solution for this problem could be that we listen to changes to timeControlStatus and deactivate the audio session once the player has really been paused.

The answer in the thread says

This error indicates that something in your app is still using audio I/O at the time when the AVAudioSession setActive:NO is being called. It’s impossible to say which object without more information, but sometimes it’s the result of calling an asynchronous stop method on a player of some sort and not waiting for the notification that the player has stopped before deactivating the audio session.

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
0

Make audio player to stop before making recording session false.. if u suppose to make audio player to be nil.. remove that line.. it works for me..