1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Player/PlaybackBar.swift

89 lines
2.5 KiB
Swift
Raw Normal View History

2021-08-23 00:43:33 +05:30
import Foundation
import SwiftUI
struct PlaybackBar: View {
2021-08-24 03:01:51 +05:30
@Environment(\.dismiss) private var dismiss
@Environment(\.inNavigationView) private var inNavigationView
@EnvironmentObject<PlayerModel> private var player
2021-08-24 03:01:51 +05:30
2021-08-23 00:43:33 +05:30
var body: some View {
HStack {
closeButton
.frame(width: 80, alignment: .leading)
2021-08-23 00:43:33 +05:30
if player.currentItem != nil {
Text(playbackStatus)
.foregroundColor(.gray)
.font(.caption2)
.frame(minWidth: 130, maxWidth: .infinity)
2021-08-23 00:43:33 +05:30
VStack {
if player.stream != nil {
Text(currentStreamString)
2021-09-14 02:11:16 +05:30
} else {
if player.currentVideo!.live {
Image(systemName: "dot.radiowaves.left.and.right")
} else {
Image(systemName: "bolt.horizontal.fill")
}
2021-09-14 02:11:16 +05:30
}
2021-08-24 03:01:51 +05:30
}
.foregroundColor(.gray)
.font(.caption2)
.frame(width: 80, alignment: .trailing)
.fixedSize(horizontal: true, vertical: true)
} else {
Spacer()
2021-08-24 03:01:51 +05:30
}
2021-08-23 00:43:33 +05:30
}
.padding(4)
.background(.black)
}
var currentStreamString: String {
"\(player.stream!.resolution.height)p"
2021-08-23 00:43:33 +05:30
}
2021-09-14 02:11:16 +05:30
var playbackStatus: String {
if player.live {
return "LIVE"
}
guard player.time != nil, player.time!.isValid else {
return "loading..."
2021-08-23 00:43:33 +05:30
}
let remainingSeconds = player.currentVideo!.length - player.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 "ends at \(timeFinishAtString)"
2021-08-23 00:43:33 +05:30
}
var closeButton: some View {
Button {
dismiss()
} label: {
Label("Close", systemImage: inNavigationView ? "chevron.backward.circle.fill" : "chevron.down.circle.fill")
.labelStyle(.iconOnly)
2021-08-23 00:43:33 +05:30
}
.accessibilityLabel(Text("Close"))
.buttonStyle(.borderless)
2021-08-23 00:43:33 +05:30
.foregroundColor(.gray)
.keyboardShortcut(.cancelAction)
}
}
2021-10-14 03:40:29 +05:30
struct PlaybackBar_Previews: PreviewProvider {
static var previews: some View {
PlaybackBar()
.injectFixtureEnvironmentObjects()
}
}