Don't duck audio for system sound

Viewed 112

I am trying to play a "ding" sound over an audio track.

When setting up the player, we have:

try AVAudioSession.sharedInstance()
                .setCategory(.playback,
                             mode: .default,
                             policy: .longFormAudio,
                             options: [])

try AVAudioSession.sharedInstance().setActive(true)

Then later on, a user action (e.g. tapping) does:

AudioServicesPlaySystemSound(SystemSoundID(1407))

This works well. The only issue is that the playing track gets ducked to play the system sound.

How can I prevent this from happening?

Strangely, in XCode simulator, the tracks play in parallel and no ducking occurs.

Update: updating to this has no effect:

 try AVAudioSession.sharedInstance()
                .setCategory(.playback,
                             mode: .default,
                             policy: .longFormAudio,
                             options: .mixWithOthers)
1 Answers

try

do{
   try AVAudioSession.sharedInstance().setCategory(.ambient)
   try AVAudioSession.sharedInstance().setActive(true, options: .notifyOthersOnDeactivation)
} catch {
   print(error.localizedDescription)
}
Related