diff --git a/ElementX/Sources/Services/Audio/Player/AudioPlayer.swift b/ElementX/Sources/Services/Audio/Player/AudioPlayer.swift index 416263d69..a0df5b2ab 100644 --- a/ElementX/Sources/Services/Audio/Player/AudioPlayer.swift +++ b/ElementX/Sources/Services/Audio/Player/AudioPlayer.swift @@ -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() { diff --git a/ElementX/Sources/Services/Audio/Recorder/AudioRecorder.swift b/ElementX/Sources/Services/Audio/Recorder/AudioRecorder.swift index d9f280357..01403ae83 100644 --- a/ElementX/Sources/Services/Audio/Recorder/AudioRecorder.swift +++ b/ElementX/Sources/Services/Audio/Recorder/AudioRecorder.swift @@ -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() } diff --git a/ElementX/Sources/Services/ElementCall/ElementCallService.swift b/ElementX/Sources/Services/ElementCall/ElementCallService.swift index 4592b132d..980e9b5f3 100644 --- a/ElementX/Sources/Services/ElementCall/ElementCallService.swift +++ b/ElementX/Sources/Services/ElementCall/ElementCallService.swift @@ -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