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
|
2021-09-25 13:48:22 +05:30
|
|
|
@EnvironmentObject private var playback: PlaybackModel
|
2021-08-24 03:01:51 +05:30
|
|
|
|
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
|
|
|
|
2021-09-14 02:11:16 +05:30
|
|
|
Text(playbackStatus)
|
2021-08-23 00:43:33 +05:30
|
|
|
.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 {
|
2021-09-25 13:48:22 +05:30
|
|
|
if playback.stream != nil {
|
2021-08-24 03:01:51 +05:30
|
|
|
Text(currentStreamString)
|
|
|
|
} else {
|
2021-09-14 02:11:16 +05:30
|
|
|
if video.live {
|
|
|
|
Image(systemName: "dot.radiowaves.left.and.right")
|
|
|
|
} else {
|
|
|
|
Image(systemName: "bolt.horizontal.fill")
|
|
|
|
}
|
2021-08-24 03:01:51 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
.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 {
|
2021-09-25 13:48:22 +05:30
|
|
|
playback.stream != nil ? "\(playback.stream!.resolution.height)p" : ""
|
2021-08-23 00:43:33 +05:30
|
|
|
}
|
|
|
|
|
2021-09-14 02:11:16 +05:30
|
|
|
var playbackStatus: String {
|
2021-09-25 13:48:22 +05:30
|
|
|
guard playback.time != nil else {
|
|
|
|
if playback.live {
|
2021-09-14 02:11:16 +05:30
|
|
|
return "LIVE"
|
|
|
|
} else {
|
|
|
|
return "loading..."
|
|
|
|
}
|
2021-08-23 00:43:33 +05:30
|
|
|
}
|
|
|
|
|
2021-09-25 13:48:22 +05:30
|
|
|
let remainingSeconds = video.length - playback.time!.seconds
|
2021-08-23 00:43:33 +05:30
|
|
|
|
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() }) {
|
2021-09-19 02:06:42 +05:30
|
|
|
Image(systemName: "xmark.circle.fill")
|
2021-08-23 00:43:33 +05:30
|
|
|
}
|
|
|
|
.accessibilityLabel(Text("Close"))
|
2021-09-01 02:47:50 +05:30
|
|
|
.buttonStyle(.borderless)
|
2021-08-23 00:43:33 +05:30
|
|
|
.foregroundColor(.gray)
|
|
|
|
.keyboardShortcut(.cancelAction)
|
|
|
|
}
|
|
|
|
}
|