Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when AVAudioSession is being "Ducked"

I'm working on a Podcast app. This plays audio using the AVAudioSessionCategoryPlayback session type. This does almost everything that I want it to do. It pauses other playing music, it gets interrupted when a call comes in and generally works exactly as I want.

With one exception. When higher priority audio gets played (for example, when running a turn-by-turn navigation app) the audio in my application gets ducked down in volume but continues to run. This creates an awful blending of the two voices that isn't desired. I would instead prefer for the audio in my application to pause during the over-played sound then continue again once it finishes.

I've tried changing the different AVAudioSession properties such as AVAudioSessionCategoryOptionMixWithOthers, but these only change how lower priority sounds are blended with my application. They do not change how mine is blended with higher priority sounds. I also tried observing the otherAudioPlaying property of the sharedSession but this didn't fire changes when I these short clips get overlayed.

Is there any way to detect when the audio in my app is being ducked so that I could instead have it paused? Or alternatively to prevent the audio of my app from being ducked so that it would treat these other sounds as interruptions?

Thanks.

like image 321
David Smith Avatar asked Aug 06 '13 14:08

David Smith


2 Answers

This feature was added in iOS 9 and can be enabled by setting your audio session mode to AVAudioSessionModeSpokenAudio. Other apps that speak such as navigation apps will interrupt your audio instead of ducking.

See: https://developer.apple.com/documentation/avfoundation/avaudiosessionmodespokenaudio

like image 123
tmoore Avatar answered Oct 06 '22 03:10

tmoore


I wrote to Apple DTS about this issue. Here is what I got back:

Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.

If you would like for Apple to consider adding support in the future to allow/notify the background app to stop playing audio when the foreground app chooses to duck other audio, then enable the background app to start audio again after ducking completed, please submit an enhancement request via the Bug Reporter tool at http://bugreport.apple.com.

Seems that it's impossible right now unfortunately.

like image 36
Martin Hering Avatar answered Oct 06 '22 02:10

Martin Hering