mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Playback state improvements
This commit is contained in:
@@ -2,25 +2,32 @@ import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct PlaybackBar: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@ObservedObject var playbackState: PlaybackState
|
||||
let video: Video
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@EnvironmentObject private var playbackState: PlaybackState
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
closeButton
|
||||
.frame(minWidth: 0, maxWidth: 60, alignment: .leading)
|
||||
.frame(width: 60, alignment: .leading)
|
||||
|
||||
Text(playbackFinishAtString)
|
||||
.foregroundColor(.gray)
|
||||
.font(.caption2)
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
.frame(minWidth: 60, maxWidth: .infinity)
|
||||
|
||||
Text(currentStreamString)
|
||||
.foregroundColor(.gray)
|
||||
.font(.caption2)
|
||||
.frame(minWidth: 0, maxWidth: 60, alignment: .trailing)
|
||||
VStack {
|
||||
if playbackState.stream != nil {
|
||||
Text(currentStreamString)
|
||||
} else {
|
||||
Image(systemName: "bolt.horizontal.fill")
|
||||
}
|
||||
}
|
||||
.foregroundColor(.gray)
|
||||
.font(.caption2)
|
||||
.frame(width: 60, alignment: .trailing)
|
||||
.fixedSize(horizontal: true, vertical: true)
|
||||
}
|
||||
.padding(4)
|
||||
.background(.black)
|
||||
@@ -37,6 +44,10 @@ struct PlaybackBar: View {
|
||||
|
||||
let remainingSeconds = video.length - playbackState.time!.seconds
|
||||
|
||||
if remainingSeconds < 60 {
|
||||
return "less than a minute"
|
||||
}
|
||||
|
||||
let timeFinishAt = Date.now.addingTimeInterval(remainingSeconds)
|
||||
let timeFinishAtString = timeFinishAt.formatted(date: .omitted, time: .shortened)
|
||||
|
||||
|
@@ -1,14 +1,15 @@
|
||||
import SwiftUI
|
||||
|
||||
struct Player: UIViewControllerRepresentable {
|
||||
@ObservedObject var playbackState: PlaybackState
|
||||
@EnvironmentObject<PlaybackState> private var playbackState
|
||||
|
||||
var video: Video?
|
||||
|
||||
func makeUIViewController(context _: Context) -> PlayerViewController {
|
||||
let controller = PlayerViewController()
|
||||
|
||||
controller.playbackState = playbackState
|
||||
controller.video = video
|
||||
controller.playbackState = playbackState
|
||||
|
||||
return controller
|
||||
}
|
||||
|
@@ -34,8 +34,7 @@ final class PlayerViewController: UIViewController {
|
||||
}
|
||||
|
||||
func loadPlayer() {
|
||||
playerState = PlayerState()
|
||||
playerState.playbackState = playbackState
|
||||
playerState = PlayerState(playbackState: playbackState)
|
||||
|
||||
guard !playerLoaded else {
|
||||
return
|
||||
|
@@ -13,11 +13,10 @@ struct VideoPlayerView: View {
|
||||
}
|
||||
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
@EnvironmentObject<PlaybackState> private var playbackState
|
||||
|
||||
@ObservedObject private var store = Store<Video>()
|
||||
|
||||
@ObservedObject private var playbackState = PlaybackState()
|
||||
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
#endif
|
||||
@@ -36,19 +35,21 @@ struct VideoPlayerView: View {
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
#if os(tvOS)
|
||||
Player(playbackState: playbackState, video: video)
|
||||
Player(video: video)
|
||||
.environmentObject(playbackState)
|
||||
#else
|
||||
GeometryReader { geometry in
|
||||
VStack(spacing: 0) {
|
||||
#if os(iOS)
|
||||
if verticalSizeClass == .regular {
|
||||
PlaybackBar(playbackState: playbackState, video: video)
|
||||
PlaybackBar(video: video)
|
||||
}
|
||||
#elseif os(macOS)
|
||||
PlaybackBar(playbackState: playbackState, video: video)
|
||||
PlaybackBar(video: video)
|
||||
#endif
|
||||
|
||||
Player(playbackState: playbackState, video: video)
|
||||
Player(video: video)
|
||||
.environmentObject(playbackState)
|
||||
.modifier(VideoPlayerSizeModifier(geometry: geometry, aspectRatio: playbackState.aspectRatio))
|
||||
}
|
||||
.background(.black)
|
||||
|
Reference in New Issue
Block a user