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:
committed by
Stefan Ceriu
parent
5c9e13b200
commit
22bb305e79
@@ -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() {
|
||||
|
||||
@@ -119,7 +119,7 @@ class AudioRecorder: AudioRecorderProtocol {
|
||||
|
||||
private func releaseAudioSession() {
|
||||
MXLog.info("releasing audio session")
|
||||
try? audioSession.setActive(false)
|
||||
try? audioSession.setActive(false, options: .notifyOthersOnDeactivation)
|
||||
removeObservers()
|
||||
}
|
||||
|
||||
|
||||
@@ -251,8 +251,6 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
|
||||
// MARK: - Private
|
||||
|
||||
func tearDownCallSession(sendEndCallAction: Bool = true) {
|
||||
try? AVAudioSession.sharedInstance().setActive(false)
|
||||
|
||||
if sendEndCallAction, let ongoingCallID {
|
||||
let transaction = CXTransaction(action: CXEndCallAction(call: ongoingCallID.callKitID))
|
||||
callController.request(transaction) { error in
|
||||
|
||||
Reference in New Issue
Block a user