0

I'm looking for a way to immediately react to the audio output being connected and disconnected to an airplay device. There are UIScreen.didConnectNotification and UIScreen.didDisconnectNotification but they will only notify when mirroring is activated in control center.

I want to highlight the airplay icon on screen while output is being routed to another device.

nontomatic
  • 2,003
  • 2
  • 24
  • 38

1 Answers1

0

And just when you're posting on StackOverflow you find the solution.

Register to MPVolumeViewWirelessRouteActiveDidChange:

NotificationCenter.default.addObserver(self,
                                       selector: #selector(checkForAirplayRouting),
                                       name: NSNotification.Name.MPVolumeViewWirelessRouteActiveDidChange,
                                       object: nil)

let volumeView: MPVolumeView!

@objc func checkForAirplayRouting() {
   //print(#function)
   volumeView.tintColor = volumeView.isWirelessRouteActive ? UIColor.orange : UIColor.white
}

This will update when the user selects an airplay device in the MPVolumeView

nontomatic
  • 2,003
  • 2
  • 24
  • 38