3

My app uses device's microphone and manages AVAudioSession.

I want to check if there is other app playing audio, if so, I want my app to stop using microphone & stop my audio session, this is what I tried (the following code is periodically triggered to check is there other app playing audio):

BOOL isPlayingWithOthers = [[AVAudioSession sharedInstance] isOtherAudioPlaying]; 
if (isPlayingWithOthers) {
   [[AVAudioSession sharedInstance] setActive:NO error:error];
}

I run my app, then, I open "My music" app, and playing a music, the above code is executed but I get the following error:

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

Why I get this error? How to solve it in my case? (My app is running on iOS7 and above)

Leem.fin
  • 40,781
  • 83
  • 202
  • 354

0 Answers0