35 lines
1.5 KiB
Swift
35 lines
1.5 KiB
Swift
import SwiftUI
|
||
import TVAnarchyCore
|
||
|
||
/// Compact transport for a view's header toolbar: previous · −10s · play/pause ·
|
||
/// +10s · next, driving the active host. Lets you control playback without
|
||
/// leaving the current tab for the Player tab. Disabled when nothing is playing
|
||
/// (no title) or the host is unreachable, so the controls never fire into a void.
|
||
struct MiniTransport: View {
|
||
@Bindable var controller: PlayerController
|
||
|
||
private var snap: PlayerController.Snapshot { controller.activeSnapshot }
|
||
private var status: PlaybackStatus { snap.status }
|
||
/// Same "nothing playing" signal the Player tab uses for its title line.
|
||
private var idle: Bool { status.title == nil }
|
||
|
||
var body: some View {
|
||
HStack(spacing: 10) {
|
||
button("backward.end.fill") { await $0.previous() }
|
||
button("gobackward.10") { await $0.seek(relative: -10) }
|
||
button(status.paused == true ? "play.fill" : "pause.fill", big: true) { await $0.playPause() }
|
||
button("goforward.10") { await $0.seek(relative: 10) }
|
||
button("forward.end.fill") { await $0.next() }
|
||
}
|
||
.disabled(idle || snap.state == .unreachable)
|
||
.help(idle ? "Nothing playing" : (status.title ?? ""))
|
||
}
|
||
|
||
private func button(_ system: String, big: Bool = false,
|
||
_ op: @escaping (any PlayerTarget) async -> Void) -> some View {
|
||
Button { controller.command(op) } label: {
|
||
Image(systemName: system).font(big ? .title3 : .body)
|
||
}
|
||
.buttonStyle(.borderless)
|
||
}
|
||
}
|