diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index 49b95c83..2370e676 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -327,9 +327,13 @@ final class MPVBackend: PlayerBackend { func closePiP(wasPlaying _: Bool) {} func updateControls() { - guard model.presentingPlayer else { + self.logger.info("updating controls") + + guard model.presentingPlayer, !model.controls.presentingOverlays else { + self.logger.info("ignored controls update") return } + DispatchQueue.main.async { [weak self] in guard let self = self else { return @@ -341,6 +345,10 @@ final class MPVBackend: PlayerBackend { } func startControlsUpdates() { + guard model.presentingPlayer, !model.controls.presentingOverlays else { + self.logger.info("ignored controls update start") + return + } self.logger.info("starting controls updates") controlsUpdates = true } diff --git a/Model/Player/PlayerControlsModel.swift b/Model/Player/PlayerControlsModel.swift index e333be07..3f216c8b 100644 --- a/Model/Player/PlayerControlsModel.swift +++ b/Model/Player/PlayerControlsModel.swift @@ -10,7 +10,7 @@ final class PlayerControlsModel: ObservableObject { @Published var presentingControls = false { didSet { handlePresentationChange() } } @Published var presentingControlsOverlay = false { didSet { handleSettingsOverlayPresentationChange() } } @Published var presentingDetailsOverlay = false { didSet { handleDetailsOverlayPresentationChange() } } - @Published var timer: Timer? + var timer: Timer? #if os(tvOS) var reporter = PassthroughSubject() diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index f412b3ff..33b1af45 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -45,6 +45,9 @@ final class PlayerModel: ObservableObject { var avPlayerBackend: AVPlayerBackend! var mpvBackend: MPVBackend! + #if !os(macOS) + var mpvController = MPVViewController() + #endif var backends: [PlayerBackend] { [avPlayerBackend, mpvBackend] @@ -190,6 +193,11 @@ final class PlayerModel: ObservableObject { networkState: networkState ) + #if !os(macOS) + mpvBackend.controller = mpvController + mpvBackend.client = mpvController.client + #endif + Defaults[.activeBackend] = .mpv playbackMode = Defaults[.playbackMode] } diff --git a/Shared/Views/MPVPlayerView.swift b/Shared/Views/MPVPlayerView.swift index fd5cdab5..8a9afa3c 100644 --- a/Shared/Views/MPVPlayerView.swift +++ b/Shared/Views/MPVPlayerView.swift @@ -2,15 +2,10 @@ import SwiftUI #if !os(macOS) struct MPVPlayerView: UIViewControllerRepresentable { - @State private var controller = MPVViewController() - @EnvironmentObject private var player func makeUIViewController(context _: Context) -> some UIViewController { - player.mpvBackend.controller = controller - player.mpvBackend.client = controller.client - - return controller + player.mpvController } func updateUIViewController(_: UIViewControllerType, context _: Context) {}