Here is what I tried
func configureAudioSession() {
let session = AVAudioSession.sharedInstance()
do {
attempt session.setCategory(.playAndRecord, choices: [.mixWithOthers, .allowBluetoothA2DP, .defaultToSpeaker])
attempt session.setActive(true)
print("Session is energetic. Present route: (session.currentRoute)")
if let bluetoothOutput = session.currentRoute.outputs.first(the place: { $0.portType == .bluetoothA2DP }) {
print("Bluetooth A2DP machine accessible: (bluetoothOutput.portName)")
// Optionally immediate consumer or deal with routing preferences
} else {
print("No Bluetooth A2DP route accessible; contemplate handbook routing through Management Heart.")
}
} catch {
print("Did not configure audio session: (error)")
}
}
Primarily, if my iPhone is streaming its audio to a close-by Apple TV, I would like my app’s audio to undergo the pair of AirPods and never Apple TV.
- I do not wanna join AirPods to the Apple TV
- I attempted the above code, however it ended up redirecting the whole system audio to AirPods/Gadget Constructed-in audio system. I do not need that — As a substitute, I would like the system audio to remain streaming to Apple TV whereas my app can by some means ship its audio to AirPods.
I am open to utilizing non-public api. Not planning on submitting this to the app retailer; it is only for a grad college acoustics mission we’re hacking on.