From 9a91b9911b23787902b3ac74dd54106ffc020bd1 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Wed, 16 Feb 2022 22:51:37 +0100 Subject: [PATCH] Prevent multiple seeks --- Model/Player/Backends/MPVClient.swift | 20 ++++++++++++++++++-- Shared/Player/Controls/PlayerControls.swift | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Model/Player/Backends/MPVClient.swift b/Model/Player/Backends/MPVClient.swift index 94450e01..37ce4c0d 100644 --- a/Model/Player/Backends/MPVClient.swift +++ b/Model/Player/Backends/MPVClient.swift @@ -15,6 +15,8 @@ final class MPVClient: ObservableObject { var glView: MPVOGLView! var backend: MPVBackend! + var seeking = false + func create(frame: CGRect) -> MPVOGLView { glView = MPVOGLView(frame: frame) @@ -121,13 +123,27 @@ final class MPVClient: ObservableObject { } func seek(relative time: CMTime, completionHandler: ((Bool) -> Void)? = nil) { - command("seek", args: [String(time.seconds)]) { _ in + guard !seeking else { + logger.warning("ignoring seek, another in progress") + return + } + + seeking = true + command("seek", args: [String(time.seconds)]) { [weak self] _ in + self?.seeking = false completionHandler?(true) } } func seek(to time: CMTime, completionHandler: ((Bool) -> Void)? = nil) { - command("seek", args: [String(time.seconds), "absolute"]) { _ in + guard !seeking else { + logger.warning("ignoring seek, another in progress") + return + } + + seeking = true + command("seek", args: [String(time.seconds), "absolute"]) { [weak self] _ in + self?.seeking = false completionHandler?(true) } } diff --git a/Shared/Player/Controls/PlayerControls.swift b/Shared/Player/Controls/PlayerControls.swift index a157ce66..397820b6 100644 --- a/Shared/Player/Controls/PlayerControls.swift +++ b/Shared/Player/Controls/PlayerControls.swift @@ -5,6 +5,7 @@ struct PlayerControls: View { static let animation = Animation.easeInOut(duration: 0) private var player: PlayerModel! + @EnvironmentObject private var model @Environment(\.verticalSizeClass) private var verticalSizeClass