feat: add Chromecast playback support
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
struct CastDeviceMenu: View {
|
||||
@ObservedObject var model: PlayerModel
|
||||
@ObservedObject private var discovery: CastDiscovery
|
||||
var icon = true
|
||||
|
||||
init(model: PlayerModel, icon: Bool = true) {
|
||||
self.model = model
|
||||
self.discovery = model.castDiscovery
|
||||
self.icon = icon
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
if let device = model.castDevice {
|
||||
Text((model.castConnecting ? "Connecting to " : "Casting to ") + device.name)
|
||||
Button(model.castConnecting ? "Cancel Casting" : "Play on This Mac") { model.stopCasting() }
|
||||
Divider()
|
||||
}
|
||||
ForEach(discovery.devices) { device in
|
||||
Button(device.name) { model.cast(to: device) }
|
||||
.disabled(!model.canCast)
|
||||
}
|
||||
if discovery.devices.isEmpty {
|
||||
Text("No Cast devices discovered")
|
||||
}
|
||||
if let error = discovery.error { Text(error) }
|
||||
Divider()
|
||||
Button("Find Cast Devices…") { discovery.start() }
|
||||
} label: {
|
||||
if icon {
|
||||
Image(systemName: "tv.badge.wifi")
|
||||
.font(.system(size: 14))
|
||||
.frame(width: 24, height: 24)
|
||||
} else {
|
||||
Text("Cast to Device")
|
||||
}
|
||||
}
|
||||
.menuStyle(.button)
|
||||
.buttonStyle(.plain)
|
||||
.menuIndicator(.hidden)
|
||||
.fixedSize()
|
||||
.accessibilityLabel("Cast to Device")
|
||||
.help(model.castDevice.map { "Casting to " + $0.name } ?? "Cast to Device")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user