Do not allow other apps play music

455 views Asked by At

We are developing a VOIP application and while there is an active call, we want not to allow other apps play music or something (like Whatsapp does).
Is there any way of doing it in a normal way, can you help please?

Edit 1:
I think we need to start with listening the observer AVAudioSessionInterruptionNotification.


Accepted Answer Edit 2:
When sound interruption begins, try to only active the AudioSession again. This works. Thank you KudoCC.

2

There are 2 answers

1
KudoCC On BEST ANSWER

Here is a link talks about audio category, there is a table in it: enter image description here

As your app supports VoIP, so it need to play and record audio, and you need interrupt non-mixable apps audio, so AVAudioSessionCategoryPlayAndRecord is the right category. Also you should re-active your audio session when you're playing/recording audio so that the category takes effect.

1
KAR On

Try this code in your app to pause the background audio when calls,

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

It is helpful when other apps uses AVAudioPlayer.

For more detail refer this Link