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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With