From eedc8f32d1fd26bad24078425aab0ee7db5d3406 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 26 Aug 2022 22:44:02 +0200 Subject: [PATCH] Improve setting audio session --- Model/Player/Backends/AVPlayerBackend.swift | 4 ---- Model/Player/Backends/MPVBackend.swift | 4 ---- Model/Player/PlayerModel.swift | 5 ----- Shared/YatteeApp.swift | 5 +++++ 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Model/Player/Backends/AVPlayerBackend.swift b/Model/Player/Backends/AVPlayerBackend.swift index e6017864..428a4099 100644 --- a/Model/Player/Backends/AVPlayerBackend.swift +++ b/Model/Player/Backends/AVPlayerBackend.swift @@ -285,10 +285,6 @@ 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 f7938a91..64f51b83 100644 --- a/Model/Player/Backends/MPVBackend.swift +++ b/Model/Player/Backends/MPVBackend.swift @@ -192,10 +192,6 @@ 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 99a1cf26..66576897 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -755,11 +755,6 @@ 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 ed85c78a..5301e983 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -247,6 +247,11 @@ struct YatteeApp: App { } } #endif + + #if !os(macOS) + try? AVAudioSession.sharedInstance().setCategory(.playback) + try? AVAudioSession.sharedInstance().setActive(true) + #endif } func migrateAccounts() {