2

Is there a way to get the AirPlay device type the iPhone is connected to? For instance, is there a way to know that the iPhone is connected to a HomePod, an Apple TV, or AirPods via AirPlay? I would like to show an icon in my app for which device the iPhone is connected to (I provide the icons). I have somewhat achieved this using

let currentRoute = AVAudioSession.sharedInstance().currentRoute
let output = currentRoute.outputs.first!
let portType = output.portType

but AVAudioSession.Port only contains the type airPlay (see link for all property types). It does not contain something like homepod, appleTV, .airpods, etc. Does anyone have a work around for this or any ideas?

Jacob Cavin
  • 2,169
  • 3
  • 19
  • 47
  • https://developer.apple.com/documentation/avfoundation/avaudiosessionportdescription -> Use the property portName which will say or contain "AirPods" if that is the hardware being used. – SierraMike Aug 30 '19 at 19:11
  • @SeanMcDonald Sadly, this does not work either. For a HomePod or an Apple TV, the portName is "Speaker". – Jacob Cavin Aug 30 '19 at 19:13

1 Answers1

4

Just ran into this myself, In addition to checking for AVAudioSession.Port.airPlay of the current AVAudioSession, you also need to check the value of the AVPlayer's isExternalPlaybackActive property. If it's true, it's AirPlaying video, if not it's just sending the audio to the HomePod or headphones.

CA Bearsfan
  • 454
  • 4
  • 20