Controls fixes

This commit is contained in:
Arkadiusz Fal
2022-03-27 21:24:32 +02:00
parent b9dfdeb23f
commit 5f15971bce
4 changed files with 59 additions and 8 deletions

View File

@@ -148,6 +148,8 @@ final class MPVBackend: PlayerBackend {
} else {
replaceItem(nil)
}
startClientUpdates()
}
func play() {

View File

@@ -11,6 +11,8 @@ final class PlayerControlsModel: ObservableObject {
@Published var timer: Timer?
@Published var playingFullscreen = false
private var throttle = Throttle(interval: 1)
var player: PlayerModel!
var playbackTime: String {
@@ -52,7 +54,13 @@ final class PlayerControlsModel: ObservableObject {
}
func show() {
player.backend.updateControls()
guard !(player?.currentItem.isNil ?? true) else {
return
}
guard !presentingControls else {
return
}
withAnimation(PlayerControls.animation) {
presentingControls = true
@@ -60,16 +68,21 @@ final class PlayerControlsModel: ObservableObject {
}
func hide() {
player?.backend.stopControlsUpdates()
guard !(player?.currentItem.isNil ?? true) else {
return
}
guard presentingControls else {
return
}
withAnimation(PlayerControls.animation) {
presentingControls = false
}
}
func toggle() {
if !presentingControls {
player.backend.updateControls()
}
withAnimation(PlayerControls.animation) {
presentingControls.toggle()
}
@@ -118,4 +131,10 @@ final class PlayerControlsModel: ObservableObject {
timer?.invalidate()
timer = nil
}
func update() {
throttle.execute { [weak self] in
self?.player?.backend.updateControls()
}
}
}