Home iOS - silent switch on with AVAudioSessionCategoryAmbient and duckOthers and mixWithOthers
Reply: 0

iOS - silent switch on with AVAudioSessionCategoryAmbient and duckOthers and mixWithOthers

Stephan Hofmann
1#
Stephan Hofmann Published in 2018-01-12 16:24:50Z

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
AVAudioSession.sharedInstance().setActive(true)
myPlayer.play()

//... when audio snipped has finished
AVAudioSession.sharedInstance().setActive(false)

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316564 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO