don’t activate AVAudioSession on app start

Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
Toni Förster 2024-08-31 13:19:54 +02:00
parent 740a2f85ac
commit 633af02577
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7
3 changed files with 19 additions and 2 deletions

View File

@ -362,8 +362,11 @@ final class AVPlayerBackend: PlayerBackend {
self.asset = nil
}
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 }

View File

@ -245,6 +245,21 @@ final class MPVBackend: PlayerBackend {
}
let startPlaying = {
#if !os(macOS)
do {
try AVAudioSession.sharedInstance().setActive(true)
NotificationCenter.default.addObserver(
self,
selector: #selector(self.handleAudioSessionInterruption(_:)),
name: AVAudioSession.interruptionNotification,
object: nil
)
} catch {
self.logger.error("Error setting up audio session: \(error)")
}
#endif
DispatchQueue.main.async { [weak self] in
guard let self else {
return

View File

@ -23,7 +23,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
// Configure the audio session for playback
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .moviePlayback)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
logger.error("Failed to set audio session category: \(error)")
}