Search code examples
iosaudioairplay

AirPlay: redirect audio by showing the available devices popup


I'm trying to implement the same AirPlay button as the Music.app. The button displays a popup with a list of available devices which the user can select to reroute the audio.

airplay-music-app

While searching about my issue, I found out the MPVolumeView but that's not what the Music.app is using. Even the Control Center is using that popup.

airplay-control-center

How can I present that popup in my app?

UPDATE:

I saw that same popup in AppStore apps as well, so it should be a Public API.

sodes-app


Solution

  • AVRoutePickerView which is available in iOS 11+ provides this interface.

    AVRoutePicketView is like a UIButton and it works in the Simulator:

    enter image description here

    let routePickerView = AVRoutePickerView(frame: .init(x: 0, y: 0, width: 40, height: 40))
    routePickerView.tintColor = .white
    view.addSubview(routePickerView)
    

    If your app supports older versions of iOS then you will need to check the version of iOS that your app is running on and use the older MPVolumeView if necessary (MPVolumeView doesn't work in the Simulator!).