From 8ce271a23486fefb2787ddd231476b4ce1755b51 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 15 Mar 2020 12:00:25 +0100 Subject: [PATCH] Fix voice messages --- lib/components/audio_player.dart | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/components/audio_player.dart b/lib/components/audio_player.dart index 881735a..946f273 100644 --- a/lib/components/audio_player.dart +++ b/lib/components/audio_player.dart @@ -37,6 +37,8 @@ class _AudioPlayerState extends State { double currentPosition = 0; double maxPosition = 0; + static String currentMxc; + @override void dispose() { if (flutterSound.audioState == t_AUDIO_STATE.IS_PLAYING) { @@ -61,6 +63,14 @@ class _AudioPlayerState extends State { } _playAction() async { + if (currentMxc != widget.content.mxc) { + if (currentMxc != null) { + if (flutterSound.audioState != t_AUDIO_STATE.IS_STOPPED) { + await flutterSound.stopPlayer(); + } + currentMxc = widget.content.mxc; + } + } switch (flutterSound.audioState) { case t_AUDIO_STATE.IS_PLAYING: await flutterSound.pausePlayer(); @@ -76,7 +86,13 @@ class _AudioPlayerState extends State { codec: t_CODEC.CODEC_AAC, ); soundSubscription ??= flutterSound.onPlayerStateChanged.listen((e) { - if (e != null) { + if (currentMxc != widget.content.mxc) { + soundSubscription?.cancel()?.then((f) => soundSubscription = null); + this.setState(() { + currentPosition = 0; + statusText = "00:00"; + }); + } else if (e != null) { DateTime date = DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt()); String txt = DateFormat('mm:ss', 'en_US').format(date);