Hey all,
I have an application I am developing and I cannot currently build to a
device. So I am asking in lieu of proper testing on my end at the moment.
1. I would like to mix my audio with that in another session (say Apple
Music is playing something). So before I play my app audio, I call this:
func activateAudioSession()
{
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayback , with: [.
duckOthers, .allowBluetoothA2DP])
try session.setActive(true)
} catch {
print("Activate session error: \(error)")
}
}
When my audio has completed playing, I call this (in all cases):
func deactivateAudioSession()
{
let session = AVAudioSession.sharedInstance()
// Do this on a separate thread because on UI thread causes 500ms
delay. This unducks others after being ducked.
DispatchQueue.global().async {
do {
try session.setActive(false)
} catch {
print("Deactivate session error: \(error)")
}
}
}
2. There might be a time when I want to stomp on any audio from another
session. In that case, I have another method I call that does NOT contain
the .duckOthers option which I take to mean that mix with others is not
enabled.
func activateAudioSessionWithStompingOthers()
{
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayback , with: [.
allowBluetoothA2DP])
try session.setActive(true)
} catch {
print("Activate session error: \(error)")
}
}
Does this seem about right?
Also - if I stomp on another session (again, say Apple Music), that session
pauses. Once that's done the user would need to manually unpause it - there
is nothing I can do programmatically to get that going again, correct?
Thanks for your attention,
Eric
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]