Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AVAudioSession AVAudioSessionCategoryPlayAndRecord mutes all push notifications sounds and vibration. Even with app in background

I'm developing an app that does some recording both when the app is in the foreground and background. Which is working. However, I've noticed that 'system' sounds like push notification alert sounds as well as vibrations are muted whenever my audio session (see below) is active. This is true even when the app is in the background.

The result is that I stop getting notification sounds/vibe for standard things like text messages, while my app is in the background and recording is on.

Audio session is set as follows:

 AVAudioSession* session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];

Evidently those sounds/vibrations are non-mixable and so I guess they get muted.

Is there any way around this (while still keeping recording active)? How can I record and still let user get push notification sounds and vibrations?

like image 699
Fraggle Avatar asked May 24 '15 13:05

Fraggle


1 Answers

You could try this:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
                                 withOptions:(AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionDuckOthers)
                                       error:nil];

Also, you could experiment with de-activating audio session using this:

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

And then re-activating it:

[[AVAudioSession sharedInstance] setActive:YES error:nil];
like image 93
ancajic Avatar answered Nov 14 '22 14:11

ancajic