2021-10-06 01:50:09 +05:30
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
struct PlayerControlsView<Content: View>: View {
|
|
|
|
let content: Content
|
|
|
|
|
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
|
|
|
@EnvironmentObject<PlayerModel> private var model
|
|
|
|
|
|
|
|
init(@ViewBuilder content: @escaping () -> Content) {
|
|
|
|
self.content = content()
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
ZStack(alignment: .bottomLeading) {
|
|
|
|
content
|
|
|
|
#if !os(tvOS)
|
2021-11-08 21:59:35 +05:30
|
|
|
.frame(minHeight: 0, maxHeight: .infinity)
|
|
|
|
.padding(.bottom, 50)
|
2021-10-06 01:50:09 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
controls
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var controls: some View {
|
2021-11-28 20:07:55 +05:30
|
|
|
let controls = HStack {
|
2021-10-06 01:50:09 +05:30
|
|
|
Button(action: {
|
2021-12-19 22:47:04 +05:30
|
|
|
model.togglePlayer()
|
2021-10-06 01:50:09 +05:30
|
|
|
}) {
|
|
|
|
HStack {
|
2021-10-23 16:57:41 +05:30
|
|
|
VStack(alignment: .leading, spacing: 3) {
|
2021-12-27 02:44:46 +05:30
|
|
|
Text(model.currentVideo?.title ?? "Not playing")
|
2021-10-23 16:57:41 +05:30
|
|
|
.font(.system(size: 14).bold())
|
|
|
|
.foregroundColor(model.currentItem.isNil ? .secondary : .accentColor)
|
|
|
|
.lineLimit(1)
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
Text(model.currentVideo?.author ?? "Yattee v\(appVersion) (build \(appBuild))")
|
2021-10-23 16:57:41 +05:30
|
|
|
.fontWeight(model.currentItem.isNil ? .light : .bold)
|
|
|
|
.font(.system(size: 10))
|
2021-10-06 01:50:09 +05:30
|
|
|
.foregroundColor(.secondary)
|
2021-10-23 16:57:41 +05:30
|
|
|
.lineLimit(1)
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2021-12-19 22:49:21 +05:30
|
|
|
.contextMenu {
|
|
|
|
Button {
|
|
|
|
model.closeCurrentItem()
|
|
|
|
} label: {
|
|
|
|
Label("Close Video", systemImage: "xmark.circle")
|
|
|
|
.labelStyle(.automatic)
|
|
|
|
}
|
|
|
|
.disabled(model.currentItem.isNil)
|
|
|
|
}
|
2021-10-23 16:57:41 +05:30
|
|
|
|
2021-10-06 01:50:09 +05:30
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
}
|
2021-10-23 16:57:41 +05:30
|
|
|
.padding(.vertical, 20)
|
2021-10-17 04:18:58 +05:30
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
ZStack(alignment: .bottom) {
|
|
|
|
HStack {
|
|
|
|
Group {
|
|
|
|
if model.isPlaying {
|
|
|
|
Button(action: {
|
|
|
|
model.pause()
|
|
|
|
}) {
|
|
|
|
Label("Pause", systemImage: "pause.fill")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button(action: {
|
|
|
|
model.play()
|
|
|
|
}) {
|
|
|
|
Label("Play", systemImage: "play.fill")
|
|
|
|
}
|
|
|
|
.disabled(model.player.currentItem.isNil)
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2021-10-23 16:57:41 +05:30
|
|
|
.font(.system(size: 30))
|
2021-10-23 02:19:31 +05:30
|
|
|
.frame(minWidth: 30)
|
2021-10-23 16:57:41 +05:30
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
Button(action: { model.advanceToNextItem() }) {
|
|
|
|
Label("Next", systemImage: "forward.fill")
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2021-10-23 02:19:31 +05:30
|
|
|
.disabled(model.queue.isEmpty)
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
ProgressView(value: progressViewValue, total: progressViewTotal)
|
|
|
|
.progressViewStyle(.linear)
|
|
|
|
#if os(iOS)
|
2021-10-23 16:57:41 +05:30
|
|
|
.offset(x: 0, y: 8)
|
2021-10-23 02:19:31 +05:30
|
|
|
.frame(maxWidth: 60)
|
|
|
|
#else
|
2021-10-23 16:57:41 +05:30
|
|
|
.offset(x: 0, y: 15)
|
2021-10-23 02:19:31 +05:30
|
|
|
.frame(maxWidth: 70)
|
|
|
|
#endif
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
.labelStyle(.iconOnly)
|
|
|
|
.padding(.horizontal)
|
2021-10-23 16:57:41 +05:30
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 55)
|
2021-10-06 01:50:09 +05:30
|
|
|
.padding(.vertical, 0)
|
2021-11-28 20:07:55 +05:30
|
|
|
.borderTop(height: 0.4, color: Color("ControlsBorderColor"))
|
|
|
|
.borderBottom(height: navigationStyle == .sidebar ? 0 : 0.4, color: Color("ControlsBorderColor"))
|
2021-10-06 01:50:09 +05:30
|
|
|
#if !os(tvOS)
|
|
|
|
.onSwipeGesture(up: {
|
2021-12-19 22:47:04 +05:30
|
|
|
model.show()
|
2021-10-06 01:50:09 +05:30
|
|
|
})
|
|
|
|
#endif
|
2021-11-28 20:07:55 +05:30
|
|
|
|
|
|
|
return Group {
|
|
|
|
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) {
|
|
|
|
controls
|
|
|
|
.background(Material.ultraThinMaterial)
|
|
|
|
} else {
|
|
|
|
controls
|
2021-12-05 22:39:25 +05:30
|
|
|
#if !os(tvOS)
|
2021-12-20 05:06:12 +05:30
|
|
|
.background(Color.secondaryBackground)
|
2021-12-05 22:39:25 +05:30
|
|
|
#endif
|
2021-11-28 20:07:55 +05:30
|
|
|
}
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
2021-10-23 02:19:31 +05:30
|
|
|
|
2021-11-09 01:37:36 +05:30
|
|
|
private var appVersion: String {
|
|
|
|
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "unknown"
|
|
|
|
}
|
|
|
|
|
2021-12-02 04:24:09 +05:30
|
|
|
private var appBuild: String {
|
|
|
|
Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "unknown"
|
|
|
|
}
|
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
private var progressViewValue: Double {
|
|
|
|
[model.time?.seconds, model.videoDuration].compactMap { $0 }.min() ?? 0
|
|
|
|
}
|
|
|
|
|
|
|
|
private var progressViewTotal: Double {
|
|
|
|
model.playerItemDuration?.seconds ?? model.currentVideo?.length ?? progressViewValue
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct PlayerControlsView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
PlayerControlsView {
|
|
|
|
VStack {
|
|
|
|
Spacer()
|
|
|
|
Text("Hello")
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|