import SwiftUI import AVKit /// Cross-platform SwiftUI wrapper around `AVRoutePickerView`. Opens the system /// route picker (AirPlay devices, Bluetooth, HomePod, Apple TV, etc.) when /// tapped. Available on iOS 11+ and macOS 10.15+ via AppKit. /// /// The actual audio routing requires `AVPlayer.allowsExternalPlayback = true` /// — see `PlayerEngine.load(...)` where the queue player is configured. #if os(iOS) struct AirPlayPickerButton: UIViewRepresentable { var tintColor: UIColor = .label var activeTintColor: UIColor = .systemGreen func makeUIView(context: Context) -> AVRoutePickerView { let view = AVRoutePickerView() view.tintColor = tintColor view.activeTintColor = activeTintColor view.prioritizesVideoDevices = false return view } func updateUIView(_ uiView: AVRoutePickerView, context: Context) { uiView.tintColor = tintColor uiView.activeTintColor = activeTintColor } } #else struct AirPlayPickerButton: NSViewRepresentable { func makeNSView(context: Context) -> AVRoutePickerView { AVRoutePickerView() } func updateNSView(_ nsView: AVRoutePickerView, context: Context) {} } #endif