mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
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
a0eafe26c3
commit
37ed7addf5
@@ -133,7 +133,7 @@ class AudioPlayer: NSObject, AudioPlayerProtocol {
|
|||||||
private func setupAudioSession() {
|
private func setupAudioSession() {
|
||||||
releaseAudioSessionTask = nil
|
releaseAudioSessionTask = nil
|
||||||
do {
|
do {
|
||||||
try audioSession.setCategory(AVAudioSession.Category.playback)
|
try audioSession.setCategory(.playback)
|
||||||
try audioSession.setActive(true)
|
try audioSession.setActive(true)
|
||||||
} catch {
|
} catch {
|
||||||
MXLog.error("Could not redirect audio playback to speakers.")
|
MXLog.error("Could not redirect audio playback to speakers.")
|
||||||
@@ -157,7 +157,7 @@ class AudioPlayer: NSObject, AudioPlayerProtocol {
|
|||||||
releaseAudioSessionTask = nil
|
releaseAudioSessionTask = nil
|
||||||
if audioSession.category == .playback, !audioSession.isOtherAudioPlaying {
|
if audioSession.category == .playback, !audioSession.isOtherAudioPlaying {
|
||||||
MXLog.info("releasing audio session")
|
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)
|
self.setInternalState(.finishedPlaying)
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.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() {
|
private func removeObservers() {
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ class AudioRecorder: AudioRecorderProtocol {
|
|||||||
|
|
||||||
private func releaseAudioSession() {
|
private func releaseAudioSession() {
|
||||||
MXLog.info("releasing audio session")
|
MXLog.info("releasing audio session")
|
||||||
try? audioSession.setActive(false)
|
try? audioSession.setActive(false, options: .notifyOthersOnDeactivation)
|
||||||
removeObservers()
|
removeObservers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -251,8 +251,6 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
|
|||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
func tearDownCallSession(sendEndCallAction: Bool = true) {
|
func tearDownCallSession(sendEndCallAction: Bool = true) {
|
||||||
try? AVAudioSession.sharedInstance().setActive(false)
|
|
||||||
|
|
||||||
if sendEndCallAction, let ongoingCallID {
|
if sendEndCallAction, let ongoingCallID {
|
||||||
let transaction = CXTransaction(action: CXEndCallAction(call: ongoingCallID.callKitID))
|
let transaction = CXTransaction(action: CXEndCallAction(call: ongoingCallID.callKitID))
|
||||||
callController.request(transaction) { error in
|
callController.request(transaction) { error in
|
||||||
|
|||||||
Reference in New Issue
Block a user