Fixes #3197 - Allow voice message playback in the background

- inform other audio sessions on deactivation
- let CallKit handle the audioSession for ElementCall
This commit is contained in:
Stefan Ceriu
2024-09-06 10:45:44 +03:00
committed by Stefan Ceriu
parent a0eafe26c3
commit 37ed7addf5
3 changed files with 3 additions and 15 deletions
@@ -133,7 +133,7 @@ class AudioPlayer: NSObject, AudioPlayerProtocol {
private func setupAudioSession() {
releaseAudioSessionTask = nil
do {
try audioSession.setCategory(AVAudioSession.Category.playback)
try audioSession.setCategory(.playback)
try audioSession.setActive(true)
} catch {
MXLog.error("Could not redirect audio playback to speakers.")
@@ -157,7 +157,7 @@ class AudioPlayer: NSObject, AudioPlayerProtocol {
releaseAudioSessionTask = nil
if audioSession.category == .playback, !audioSession.isOtherAudioPlaying {
MXLog.info("releasing audio session")
try? audioSession.setActive(false)
try? audioSession.setActive(false, options: .notifyOthersOnDeactivation)
}
}
@@ -209,16 +209,6 @@ class AudioPlayer: NSObject, AudioPlayerProtocol {
self.setInternalState(.finishedPlaying)
}
.store(in: &cancellables)
// Pause playback uppon UIApplication.didBecomeActiveNotification notification
NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)
.sink { [weak self] _ in
guard let self else { return }
self.pause()
// Release the audio session right away, as we don't play audio in the background
self.releaseAudioSession()
}
.store(in: &cancellables)
}
private func removeObservers() {