2021-07-19 04:02:46 +05:30
|
|
|
import AVKit
|
|
|
|
import Siesta
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct VideoPlayerView: View {
|
2021-09-19 02:06:42 +05:30
|
|
|
static let defaultAspectRatio: Double = 1.77777778
|
|
|
|
static var defaultMinimumHeightLeft: Double {
|
2021-08-23 00:43:33 +05:30
|
|
|
#if os(macOS)
|
|
|
|
300
|
|
|
|
#else
|
|
|
|
200
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
@StateObject private var store = Store<Video>()
|
2021-07-19 04:02:46 +05:30
|
|
|
|
2021-08-23 00:43:33 +05:30
|
|
|
#if os(iOS)
|
|
|
|
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
|
|
|
#endif
|
2021-08-17 04:16:18 +05:30
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
@EnvironmentObject<InvidiousAPI> private var api
|
|
|
|
@EnvironmentObject<PlaybackModel> private var playback
|
|
|
|
|
2021-07-19 04:02:46 +05:30
|
|
|
var resource: Resource {
|
2021-09-25 13:48:22 +05:30
|
|
|
api.video(video.id)
|
2021-07-19 04:02:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
var video: Video
|
|
|
|
|
|
|
|
init(_ video: Video) {
|
|
|
|
self.video = video
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
2021-08-23 00:43:33 +05:30
|
|
|
VStack(spacing: 0) {
|
|
|
|
#if os(tvOS)
|
2021-08-24 03:01:51 +05:30
|
|
|
Player(video: video)
|
2021-09-25 13:48:22 +05:30
|
|
|
.environmentObject(playback)
|
2021-08-23 00:43:33 +05:30
|
|
|
#else
|
|
|
|
GeometryReader { geometry in
|
|
|
|
VStack(spacing: 0) {
|
|
|
|
#if os(iOS)
|
|
|
|
if verticalSizeClass == .regular {
|
2021-08-24 03:01:51 +05:30
|
|
|
PlaybackBar(video: video)
|
2021-08-23 00:43:33 +05:30
|
|
|
}
|
|
|
|
#elseif os(macOS)
|
2021-08-24 03:01:51 +05:30
|
|
|
PlaybackBar(video: video)
|
2021-08-23 00:43:33 +05:30
|
|
|
#endif
|
|
|
|
|
2021-08-24 03:01:51 +05:30
|
|
|
Player(video: video)
|
2021-09-25 13:48:22 +05:30
|
|
|
.environmentObject(playback)
|
|
|
|
.modifier(VideoPlayerSizeModifier(geometry: geometry, aspectRatio: playback.aspectRatio))
|
2021-08-02 02:55:50 +05:30
|
|
|
}
|
2021-08-23 00:43:33 +05:30
|
|
|
.background(.black)
|
|
|
|
|
|
|
|
VStack(spacing: 0) {
|
|
|
|
#if os(iOS)
|
|
|
|
if verticalSizeClass == .regular {
|
|
|
|
ScrollView(.vertical, showsIndicators: showScrollIndicators) {
|
|
|
|
if let video = store.item {
|
|
|
|
VideoDetails(video: video)
|
|
|
|
} else {
|
|
|
|
VideoDetails(video: video)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if let video = store.item {
|
|
|
|
VideoDetails(video: video)
|
|
|
|
} else {
|
|
|
|
VideoDetails(video: video)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2021-09-25 13:48:22 +05:30
|
|
|
.modifier(VideoDetailsPaddingModifier(geometry: geometry, aspectRatio: playback.aspectRatio))
|
2021-07-19 04:02:46 +05:30
|
|
|
}
|
2021-09-25 13:48:22 +05:30
|
|
|
.animation(.linear(duration: 0.2), value: playback.aspectRatio)
|
2021-07-19 04:02:46 +05:30
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.onAppear {
|
2021-09-25 13:48:22 +05:30
|
|
|
resource.addObserver(store)
|
2021-07-19 04:02:46 +05:30
|
|
|
resource.loadIfNeeded()
|
|
|
|
}
|
|
|
|
.onDisappear {
|
|
|
|
resource.removeObservers(ownedBy: store)
|
|
|
|
resource.invalidate()
|
|
|
|
}
|
2021-08-02 02:55:50 +05:30
|
|
|
#if os(macOS)
|
2021-08-23 00:43:33 +05:30
|
|
|
.frame(maxWidth: 1000, minHeight: 700)
|
2021-07-19 04:02:46 +05:30
|
|
|
#elseif os(iOS)
|
2021-09-01 02:47:50 +05:30
|
|
|
.navigationBarHidden(true)
|
2021-07-19 04:02:46 +05:30
|
|
|
#endif
|
|
|
|
}
|
2021-08-23 00:43:33 +05:30
|
|
|
|
|
|
|
var showScrollIndicators: Bool {
|
|
|
|
#if os(macOS)
|
|
|
|
false
|
|
|
|
#else
|
|
|
|
true
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct VideoPlayerView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
VStack {
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.sheet(isPresented: .constant(true)) {
|
|
|
|
VideoPlayerView(Video.fixture)
|
2021-09-29 17:15:00 +05:30
|
|
|
.injectFixtureEnvironmentObjects()
|
2021-08-23 00:43:33 +05:30
|
|
|
}
|
|
|
|
}
|
2021-07-19 04:02:46 +05:30
|
|
|
}
|