Reputation: 9
Here's what I attempted
func configureAudioSession() {
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(.playAndRecord, options: [.mixWithOthers, .allowBluetoothA2DP, .defaultToSpeaker])
try session.setActive(true)
print("Session is active. Current route: \(session.currentRoute)")
if let bluetoothOutput = session.currentRoute.outputs.first(where: { $0.portType == .bluetoothA2DP }) {
print("Bluetooth A2DP device available: \(bluetoothOutput.portName)")
// Optionally prompt user or handle routing preferences
} else {
print("No Bluetooth A2DP route available; consider manual routing via Control Center.")
}
} catch {
print("Failed to configure audio session: \(error)")
}
}
Essentially, if my iPhone is streaming its audio to a nearby Apple TV, I want my app's audio to go through the pair of AirPods and not Apple TV.
I'm open to using private api. Not planning on submitting this to the app store; it's just for a grad school acoustics project we're hacking on.
Upvotes: 0
Views: 32