in my iOS app, I\'m trying to implement \"ducking\": while my app plays a short \"command-like\" sound, any background music should be lowered in volume. Having finished pla
A Swift 5 solution to this:
// Create a background serial queue to call AVAudioPlayer.setActive() on
queue = DispatchQueue(label: "backgroundAudio", qos: .userInitiated, attributes: [], autoreleaseFrequency: .inherit, target: nil)
// ... sometime later, activate or deactivate the audio instance
queue.async {
do {
try AVAudioSession.sharedInstance().setActive(false, options: [/* my options */])
} catch {
print("AVAudioSession.sharedInstance().setActive(false) failed: \(error)")
}
}