Question

I have an application which uses Audio Queues to do recording of spoken user input. This only happens for short durations and only when the user presses a button.

I'd like to allow the user's background music to continue playing, except have it muted or playing at a much lower volume whenever the recording is actually taking place (to avoid recording the audio playing out of the speaker).

For my recording queue, I'm using the PlayAndRecord category, and I have the OverrideCategoryMixWithOthers property set to true.

Was it helpful?

Solution

This problem became less of an issue in iOS4+, when they added the AudioSessionSetActiveWithFlags API and the kAudioSessionSetActiveFlag_NotifyOthersOnDeactivation flag.

To pause background music while recording, you need to call AudioSessionSetActive(false), which will deactivate your audio session, then switch categories to PlayAndRecord mode, and set the OverrideCategoryMixWithOthers property to false.

Now, reactivate your session with AudioSessionSetActive(true) with these settings, the audio session for iPod/Pandora/etc will be interrupted and will fade-out and pause.

Then, when your recording is finished, deactivate your session again using

AudioSessionSetActiveWithFlags(false, kAudioSessionSetActiveFlag_NotifyOthersOnDeactivation);

This will notify the background music apps that their session is no longer interrupted and they can begin playing music.

Finally, you can set up your audio session again using MediaPlayback (or equiv.) mode and setting the OverrideCategoryMixWithOthers property to true again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top