2021-08-22 19:13:33 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlaybackBar: View {
|
|
|
|
let video: Video
|
|
|
|
|
2021-08-23 21:31:51 +00:00
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@EnvironmentObject private var playbackState: PlaybackState
|
|
|
|
|
2021-08-22 19:13:33 +00:00
|
|
|
var body: some View {
|
|
|
|
HStack {
|
|
|
|
closeButton
|
2021-08-23 21:31:51 +00:00
|
|
|
.frame(width: 60, alignment: .leading)
|
2021-08-22 19:13:33 +00:00
|
|
|
|
|
|
|
Text(playbackFinishAtString)
|
|
|
|
.foregroundColor(.gray)
|
|
|
|
.font(.caption2)
|
2021-08-23 21:31:51 +00:00
|
|
|
.frame(minWidth: 60, maxWidth: .infinity)
|
2021-08-22 19:13:33 +00:00
|
|
|
|
2021-08-23 21:31:51 +00:00
|
|
|
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)
|
2021-08-22 19:13:33 +00:00
|
|
|
}
|
|
|
|
.padding(4)
|
|
|
|
.background(.black)
|
|
|
|
}
|
|
|
|
|
|
|
|
var currentStreamString: String {
|
|
|
|
playbackState.stream != nil ? "\(playbackState.stream!.resolution.height)p" : ""
|
|
|
|
}
|
|
|
|
|
|
|
|
var playbackFinishAtString: String {
|
|
|
|
guard playbackState.time != nil else {
|
|
|
|
return "loading..."
|
|
|
|
}
|
|
|
|
|
|
|
|
let remainingSeconds = video.length - playbackState.time!.seconds
|
|
|
|
|
2021-08-23 21:31:51 +00:00
|
|
|
if remainingSeconds < 60 {
|
|
|
|
return "less than a minute"
|
|
|
|
}
|
|
|
|
|
2021-08-22 19:13:33 +00:00
|
|
|
let timeFinishAt = Date.now.addingTimeInterval(remainingSeconds)
|
|
|
|
let timeFinishAtString = timeFinishAt.formatted(date: .omitted, time: .shortened)
|
|
|
|
|
|
|
|
return "finishes at \(timeFinishAtString)"
|
|
|
|
}
|
|
|
|
|
|
|
|
var closeButton: some View {
|
|
|
|
Button(action: { dismiss() }) {
|
|
|
|
Image(systemName: "chevron.down.circle.fill")
|
|
|
|
}
|
|
|
|
.accessibilityLabel(Text("Close"))
|
|
|
|
.buttonStyle(BorderlessButtonStyle())
|
|
|
|
.foregroundColor(.gray)
|
|
|
|
.keyboardShortcut(.cancelAction)
|
|
|
|
}
|
|
|
|
}
|