1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Player/VideoPlayerView.swift

59 lines
1.5 KiB
Swift
Raw Normal View History

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 {
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)
}
.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
}
#if os(macOS)
2021-07-19 04:02:46 +05:30
.navigationTitle(video.title)
#elseif os(iOS)
.navigationBarTitle(video.title, displayMode: .inline)
#endif
}
}