From 1155c02b3f9718a95a745ea83ce051e15897bc6c Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Fri, 28 Feb 2025 09:23:52 -0500 Subject: [PATCH] chore: after adding to stop audio stream to stop other audio messages on play another audio message, wait for stream to go through before playing so it doesn't stop the just-clicked audio (#1983) --- lib/pages/chat/events/audio_player.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index 260b49d49..e99036f66 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -171,8 +171,11 @@ class AudioPlayerState extends State { void _playAction() async { final audioPlayer = this.audioPlayer ??= AudioPlayer(); // #Pangea - // if there's another audio playing, stop it + // If there's another audio playing, stop it. Wait for this to come through + // the stream so that the listener doesn't stop the audio that just started + final future = widget.chatController.stopAudioStream.stream.first; widget.chatController.stopAudioStream.add(null); + await future; // if (AudioPlayerWidget.currentId != widget.event.eventId) { if (AudioPlayerWidget.currentId != widget.event?.eventId) { @@ -363,8 +366,7 @@ class AudioPlayerState extends State { : _downloadAction(); } - _onShowToolbar = - widget.chatController.stopAudioStream.stream.listen((eventID) { + _onShowToolbar = widget.chatController.stopAudioStream.stream.listen((_) { audioPlayer?.pause(); audioPlayer?.seek(Duration.zero); });