Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 953
xuyafei Avatar asked Feb 24 '17 07:02

xuyafei


2 Answers

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.

like image 181
NSNoob Avatar answered Nov 20 '22 03:11

NSNoob


@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.

like image 1
Lance Samaria Avatar answered Nov 20 '22 03:11

Lance Samaria