AVRoutePickerView
A view that presents a list of nearby media receivers.
Declaration
class AVRoutePickerViewOverview
This view represents a button that users tap to stream audio/video content to a media receiver, such as a Mac or Apple TV.
[Image]
When the user taps the button, the system presents a popover that displays all of the nearby AirPlay devices that can receive and play back media. If your app prefers video content, the system displays video-capable devices higher in the list.
[Image]
In iOS 16 and later, you can add devices to the list that implement custom protocols. For more information about displaying third-party routes, see AVRouting.
Configure the button’s text, color, and media preference
The following code example creates the view alongside custom text:
HStack {
Text("Choose output device")
.font(.title)
.frame(maxWidth: .infinity, alignment: .center)
.fixedSize()
.padding(.leading)
if routeDetected {
DevicePickerView() // See implementation below.
.frame(width: 60, height: 60)
.padding(.trailing)
}
}Your app configures the button’s color scheme and indicates whether your app prefers video content, as the following code demonstrates:
struct DevicePickerView: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
let routePickerView = AVRoutePickerView()
// Configure the button's color.
routePickerView.delegate = context.coordinator
routePickerView.backgroundColor = UIColor.white
routePickerView.tintColor = UIColor.black
// Indicate whether your app prefers video content.
routePickerView.prioritizesVideoDevices = true
return routePickerViewTopics
Configuring the delegate
Configuring the route picker view
activeTintColorisRoutePickerButtonBorderedprioritizesVideoDevicesroutePickerButtonStyleAVRoutePickerViewButtonStyleroutePickerButtonColor(for:)setRoutePickerButtonColor(_:for:)AVRoutePickerView.ButtonState