From b90a726f875d77cf3995f44d35d0c15ec00dfcdf Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 5 Jun 2022 19:12:00 +0200 Subject: [PATCH] Don't draw player when in background --- Model/Player/PlayerModel.swift | 6 ++++++ Shared/YatteeApp.swift | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index d0c336f4..a2270699 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -446,6 +446,8 @@ final class PlayerModel: ObservableObject { } #else func handleEnterForeground() { + setNeedsDrawing(true) + guard closePiPAndOpenPlayerOnEnteringForeground, playingInPictureInPicture else { return } @@ -454,6 +456,10 @@ final class PlayerModel: ObservableObject { closePiP() } + func handleEnterBackground() { + setNeedsDrawing(false) + } + func enterFullScreen() { guard !controls.playingFullscreen else { return diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index 2ec75b47..7d56af85 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -61,6 +61,11 @@ struct YatteeApp: App { ) { _ in player.handleEnterForeground() } + .onReceive( + NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification) + ) { _ in + player.handleEnterBackground() + } #endif #if os(iOS) .handlesExternalEvents(preferring: Set(["*"]), allowing: Set(["*"]))