2021-08-23 00:43:33 +05:30
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlaybackBar: View {
|
|
|
|
let video: Video
|
|
|
|
|
2021-08-24 03:01:51 +05:30
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
@EnvironmentObject private var playbackState: PlaybackState
|
|
|
|
|
2021-08-23 00:43:33 +05:30
|
|
|
var body: some View {
|
|
|
|
HStack {
|
|
|
|
closeButton
|
2021-08-24 03:01:51 +05:30
|
|
|
.frame(width: 60, alignment: .leading)
|
2021-08-23 00:43:33 +05:30
|
|
|
|
|
|
|
Text(playbackFinishAtString)
|
|
|
|
.foregroundColor(.gray)
|
|
|
|
.font(.caption2)
|
2021-08-24 03:01:51 +05:30
|
|
|
.frame(minWidth: 60, maxWidth: .infinity)
|
2021-08-23 00:43:33 +05:30
|
|
|
|
2021-08-24 03:01:51 +05:30
|
|
|
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-23 00:43:33 +05:30
|
|
|
}
|
|
|
|
.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-24 03:01:51 +05:30
|
|
|
if remainingSeconds < 60 {
|
|
|
|
return "less than a minute"
|
|
|
|
}
|
|
|
|
|
2021-08-23 00:43:33 +05:30
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|