i have a question about AVAudioSession. I want to duck and mix running music (from spotify for example) when my snippet is played but it should be also silenced by the Ring/Silent switch.
In my app I play a short audio snippet like this:
//set my cateory first
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient, with: [.duckOthers])
//... when audio will start playing
//... when audio snipped has finished
This works fine when the Ring/Silent switch is off. The music gets ducked and my audio snipped is played. After the audio finished the music gets in the foreground.
Now when the Ring/Silent switch is on my snippet is not played but the running music gets ducked which is not the behaviour which I want.
So is there any combination or solution to silence audio when the switch is on and duck other audios when my current session is active?
I found those repos (Mute, SoundSwitch) about detecting the mute switch but this looks dirty to me.