2021-07-19 04:02:46 +05:30
|
|
|
import AVKit
|
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoPlayerView: View {
|
|
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
|
|
|
|
|
|
|
@ObservedObject private var store = Store<Video>()
|
|
|
|
|
2021-08-17 04:16:18 +05:30
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
|
2021-07-19 04:02:46 +05:30
|
|
|
var resource: Resource {
|
|
|
|
InvidiousAPI.shared.video(video.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
var video: Video
|
|
|
|
|
|
|
|
init(_ video: Video) {
|
|
|
|
self.video = video
|
|
|
|
resource.addObserver(store)
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
2021-08-02 02:55:50 +05:30
|
|
|
Player(video: video)
|
|
|
|
.frame(alignment: .leading)
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
ScrollView(.vertical) {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(video.title)
|
|
|
|
Text(video.author)
|
2021-08-17 04:16:18 +05:30
|
|
|
|
|
|
|
Button("Done") {
|
|
|
|
dismiss()
|
|
|
|
}
|
|
|
|
.keyboardShortcut(.cancelAction)
|
2021-08-02 02:55:50 +05:30
|
|
|
}
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
2021-07-19 04:02:46 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.onAppear {
|
|
|
|
resource.loadIfNeeded()
|
|
|
|
}
|
|
|
|
.onDisappear {
|
|
|
|
resource.removeObservers(ownedBy: store)
|
|
|
|
resource.invalidate()
|
|
|
|
|
|
|
|
navigationState.showingVideoDetails = navigationState.returnToDetails
|
|
|
|
}
|
2021-08-02 02:55:50 +05:30
|
|
|
#if os(macOS)
|
2021-07-19 04:02:46 +05:30
|
|
|
.navigationTitle(video.title)
|
|
|
|
#elseif os(iOS)
|
|
|
|
.navigationBarTitle(video.title, displayMode: .inline)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|