Evan Kaminsky
Evan Kaminsky

Reputation: 715

Open native iOS audio output destination picker in-app

I would like to open iOS' native audio destination picker UI inside of my application (pictured below). Is there a way to do this with AVAudioSession?

iOS Native Audio Output Picker

Upvotes: 5

Views: 2388

Answers (1)

Evan Kaminsky
Evan Kaminsky

Reputation: 715

This is the control I was looking for: https://developer.apple.com/documentation/avkit/avroutepickerview. It appears on screen as a button (with the default AirPlay 2 icon) and handles all of the logic for you.

Example

import AVKit

let audioPicker = AVRoutePickerView(frame: ...)
addSubview(audioPicker)

You can subscribe to audio route updates with the following:

NotificationCenter.default.addObserver(self, selector: ...), name: AVAudioSession.routeChangeNotification, object: nil)

Upvotes: 10

Related Questions