Looks like I have found the
—
basics :
Down vote
Here's what I am using for Swift 2.0:
let sess = AVAudioSession.sharedInstance()
if sess.otherAudioPlaying {
= try? sess.setCategory(AVAudioSessionCategoryAmbient, withOptions: .DuckOthers)
= try? sess.setActive(true, withOptions: [])
}
Please note that you can replace .DuckOthers with [] if you don't want to lower background music and instead play on top to it.
Enumeration Case
AVAudioSessionCategoryOptionDuckOthers
An option that reduces the volume of other audio session while audio from this session plays.
Availability
iOS 6.0+
macOS 10.15+
Mac Catalyst 13.0+
tvOS 9.0+
watchOS 7.0+
Framework
AVFoundation
On This Page
Declaration
Discussion
See Also
Declaration
AVAudioSessionCategoryOptionDuckOthers = 0x2
Discussion
You can set this option only if the audio session category is AVAudioSessionCategoryPlayAndRecord, AVAudioSessionCategoryPlayback, or AVAudioSessionCategoryMultiRoute. Setting it implicitly sets the AVAudioSessionCategoryOptionMixWithOthers option.
Use this option to mix your app’s audio with that of others. While your app plays its audio, the system reduces the volume of other audio sessions to make yours more prominent. If your app provides occasional spoken audio, such as in a turn-by-turn navigation app or an exercise app, you should also set the AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers option.
Note that ducking begins when you activate your app’s audio session and ends when you deactivate the session. If you clear this option, activating your session interrupts other audio sessions.
See Also
Post
Replies
Boosts
Views
Activity
There are at least few apps that incorporate “audio mixing”
one of them is EMS radio,
it maintains audio stream regardless of the user plays another audio file/online audio radio.
additionally, “ police scanner radio and fire”,
the settings within this app have “audio mixing” feature.
so information provided above is incorrect.