2021-06-11 04:20:10 +05:30
|
|
|
import AVKit
|
|
|
|
import Foundation
|
2021-06-28 16:13:07 +05:30
|
|
|
import Siesta
|
2021-06-11 04:20:10 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerView: View {
|
2021-06-28 16:13:07 +05:30
|
|
|
@ObservedObject private var store = Store<Video>()
|
|
|
|
|
|
|
|
let resource: Resource
|
2021-06-11 05:35:59 +05:30
|
|
|
|
|
|
|
init(id: String) {
|
2021-06-28 16:13:07 +05:30
|
|
|
resource = InvidiousAPI.shared.video(id)
|
|
|
|
resource.addObserver(store)
|
2021-06-11 05:35:59 +05:30
|
|
|
}
|
2021-06-11 04:20:10 +05:30
|
|
|
|
|
|
|
var body: some View {
|
2021-06-17 00:42:41 +05:30
|
|
|
VStack {
|
2021-07-12 02:22:49 +05:30
|
|
|
#if os(tvOS)
|
|
|
|
pvc
|
|
|
|
.edgesIgnoringSafeArea(.all)
|
|
|
|
#else
|
|
|
|
if let video = store.item {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(video.title)
|
|
|
|
|
|
|
|
.bold()
|
|
|
|
|
|
|
|
Text("\(video.author)")
|
|
|
|
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.bold()
|
|
|
|
|
|
|
|
if !video.published.isEmpty || video.views != 0 {
|
|
|
|
HStack(spacing: 8) {
|
|
|
|
#if os(iOS)
|
|
|
|
Text(video.playTime ?? "?")
|
|
|
|
.layoutPriority(1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if !video.published.isEmpty {
|
|
|
|
Image(systemName: "calendar")
|
|
|
|
Text(video.published)
|
|
|
|
.lineLimit(1)
|
|
|
|
.truncationMode(.middle)
|
|
|
|
}
|
|
|
|
|
|
|
|
if video.views != 0 {
|
|
|
|
Image(systemName: "eye")
|
|
|
|
Text(video.viewsCount)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.padding(.top)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.padding()
|
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2021-06-11 04:20:10 +05:30
|
|
|
}
|
2021-06-28 16:13:07 +05:30
|
|
|
.onAppear {
|
|
|
|
resource.loadIfNeeded()
|
2021-06-11 04:20:10 +05:30
|
|
|
}
|
|
|
|
}
|
2021-06-17 00:42:41 +05:30
|
|
|
|
2021-07-12 04:53:04 +05:30
|
|
|
// swiftlint:disable implicit_return
|
2021-07-12 02:22:49 +05:30
|
|
|
#if !os(macOS)
|
|
|
|
var pvc: PlayerViewController? {
|
|
|
|
guard store.item != nil else {
|
|
|
|
return nil
|
|
|
|
}
|
2021-06-17 00:42:41 +05:30
|
|
|
|
2021-07-12 02:22:49 +05:30
|
|
|
return PlayerViewController(video: store.item!)
|
|
|
|
}
|
|
|
|
#endif
|
2021-07-12 04:53:04 +05:30
|
|
|
// swiftlint:enable implicit_return
|
2021-06-11 04:20:10 +05:30
|
|
|
}
|