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)

This commit is contained in:
ggurdin 2025-02-28 09:23:52 -05:00 committed by GitHub
parent 912efa7bb8
commit 1155c02b3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -171,8 +171,11 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
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<AudioPlayerWidget> {
: _downloadAction();
}
_onShowToolbar =
widget.chatController.stopAudioStream.stream.listen((eventID) {
_onShowToolbar = widget.chatController.stopAudioStream.stream.listen((_) {
audioPlayer?.pause();
audioPlayer?.seek(Duration.zero);
});