Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 516
Evan Kaminsky Avatar asked Feb 28 '19 20:02

Evan Kaminsky


1 Answers

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)
like image 55
Evan Kaminsky Avatar answered Nov 10 '22 02:11

Evan Kaminsky