2021-07-18 22:32:46 +00:00
|
|
|
import AVKit
|
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoPlayerView: View {
|
|
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
|
|
|
|
|
|
|
@ObservedObject private var store = Store<Video>()
|
|
|
|
|
|
|
|
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-01 21:25:50 +00:00
|
|
|
Player(video: video)
|
|
|
|
.frame(alignment: .leading)
|
|
|
|
|
|
|
|
#if !os(tvOS)
|
|
|
|
ScrollView(.vertical) {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(video.title)
|
|
|
|
Text(video.author)
|
|
|
|
}
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
2021-07-18 22:32:46 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.onAppear {
|
|
|
|
resource.loadIfNeeded()
|
|
|
|
}
|
|
|
|
.onDisappear {
|
|
|
|
resource.removeObservers(ownedBy: store)
|
|
|
|
resource.invalidate()
|
|
|
|
|
|
|
|
navigationState.showingVideoDetails = navigationState.returnToDetails
|
|
|
|
}
|
2021-08-01 21:25:50 +00:00
|
|
|
#if os(macOS)
|
2021-07-18 22:32:46 +00:00
|
|
|
.navigationTitle(video.title)
|
|
|
|
#elseif os(iOS)
|
|
|
|
.navigationBarTitle(video.title, displayMode: .inline)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|