From 9e076f8b5f0688fdb433cd872f58ab9ad1ef59b6 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 3 Apr 2022 17:03:56 +0200 Subject: [PATCH] Fix #86 --- Model/Player/Backends/MPVBackend.swift | 10 ++++++++++ Model/Player/PlayerModel.swift | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index b15fcf51..6092e82f 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -39,6 +39,10 @@ final class MPVBackend: PlayerBackend { } updateControlsIsPlaying() + + #if !os(macOS) + UIApplication.shared.isIdleTimerDisabled = model.presentingPlayer && isPlaying + #endif }} var playerItemDuration: CMTime? @@ -77,6 +81,12 @@ final class MPVBackend: PlayerBackend { func playStream(_ stream: Stream, of video: Video, preservingTime: Bool, upgrading _: Bool) { handleEOF = false + #if !os(macOS) + if model.presentingPlayer { + UIApplication.shared.isIdleTimerDisabled = true + } + #endif + let updateCurrentStream = { DispatchQueue.main.async { [weak self] in self?.stream = stream diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index e7f504ea..cacb71de 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -299,6 +299,10 @@ final class PlayerModel: ObservableObject { backend.setNeedsDrawing(presentingPlayer) controls.hide() + #if !os(macOS) + UIApplication.shared.isIdleTimerDisabled = presentingPlayer + #endif + if presentingPlayer, closePiPOnOpeningPlayer, playingInPictureInPicture { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in self?.closePiP()