From dbc17047513bedc7a7dfc95f409dbafe6396d7f4 Mon Sep 17 00:00:00 2001 From: Nicolas Mauri Date: Mon, 30 Oct 2023 20:44:59 +0100 Subject: [PATCH] Fix the delay when switching between voice messages (#1985) --- ElementX/Sources/Services/Audio/Player/AudioPlayer.swift | 1 - .../TimelineController/RoomTimelineController.swift | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ElementX/Sources/Services/Audio/Player/AudioPlayer.swift b/ElementX/Sources/Services/Audio/Player/AudioPlayer.swift index e14143b8a..331fb48f9 100644 --- a/ElementX/Sources/Services/Audio/Player/AudioPlayer.swift +++ b/ElementX/Sources/Services/Audio/Player/AudioPlayer.swift @@ -119,7 +119,6 @@ class AudioPlayer: NSObject, AudioPlayerProtocol { isStopped = true internalAudioPlayer?.pause() internalAudioPlayer?.seek(to: .zero) - try? AVAudioSession.sharedInstance().setActive(false) } func seek(to progress: Double) async { diff --git a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift index 3b4a248c9..fbd443e3d 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift @@ -284,16 +284,15 @@ class RoomTimelineController: RoomTimelineControllerProtocol { let audioPlayerState = audioPlayerState(for: itemID) - // Detach all other states - await mediaPlayerProvider.detachAllStates(except: audioPlayerState) // Ensure this one is attached if !audioPlayerState.isAttached { audioPlayerState.attachAudioPlayer(audioPlayer) } + // Detach all other states + await mediaPlayerProvider.detachAllStates(except: audioPlayerState) + guard audioPlayer.mediaSource == source, audioPlayer.state != .error else { - audioPlayer.stop() - // Load content do { MXLog.info("Loading voice message audio content from source for itemID \(itemID)")