From a7a3e0827d5770f62f03cf85ec756138da2af3be Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 23 Sep 2022 20:36:10 +0200 Subject: [PATCH] Revert "Improve setting audio session" This reverts commit eedc8f32d1fd26bad24078425aab0ee7db5d3406. Fix #307 --- Model/Player/Backends/AVPlayerBackend.swift | 4 ++++ Model/Player/Backends/MPVBackend.swift | 4 ++++ Model/Player/PlayerModel.swift | 5 +++++ Shared/YatteeApp.swift | 5 ----- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Model/Player/Backends/AVPlayerBackend.swift b/Model/Player/Backends/AVPlayerBackend.swift index c388eaad..84ac1f1c 100644 --- a/Model/Player/Backends/AVPlayerBackend.swift +++ b/Model/Player/Backends/AVPlayerBackend.swift @@ -276,6 +276,10 @@ final class AVPlayerBackend: PlayerBackend { } let startPlaying = { + #if !os(macOS) + try? AVAudioSession.sharedInstance().setActive(true) + #endif + self.setRate(self.model.currentRate) guard let item = self.model.playerItem, self.isAutoplaying(item) else { return } diff --git a/Model/Player/Backends/MPVBackend.swift b/Model/Player/Backends/MPVBackend.swift index 9868bce9..1f12fe47 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -182,6 +182,10 @@ final class MPVBackend: PlayerBackend { } let startPlaying = { + #if !os(macOS) + try? AVAudioSession.sharedInstance().setActive(true) + #endif + DispatchQueue.main.async { [weak self] in guard let self = self else { return diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 557ca41d..7b0dbe1b 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -714,6 +714,11 @@ final class PlayerModel: ObservableObject { remoteCommandCenterConfigured = true #if !os(macOS) + try? AVAudioSession.sharedInstance().setCategory( + .playback, + mode: .moviePlayback + ) + UIApplication.shared.beginReceivingRemoteControlEvents() #endif diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index 2a199f07..8233fac1 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -238,11 +238,6 @@ struct YatteeApp: App { } } #endif - - #if !os(macOS) - try? AVAudioSession.sharedInstance().setCategory(.playback) - try? AVAudioSession.sharedInstance().setActive(true) - #endif } func migrateAccounts() {