From d22cc595e0f1b005b9434f39295239a7ccd99e1c Mon Sep 17 00:00:00 2001 From: Hermannschule <129524255+hermanncoders@users.noreply.github.com> Date: Sun, 16 Jul 2023 20:02:31 +0200 Subject: [PATCH] fix audio not stopping and returning to start after finishing --- lib/pages/chat/events/audio_player.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index d5beeadaba..4c6b9ebce3 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -42,6 +42,7 @@ class AudioPlayerState extends State { String? statusText; int currentPosition = 0; double maxPosition = 0; + double thisPosition = 0; MatrixFile? matrixFile; File? audioFile; @@ -118,7 +119,13 @@ class AudioPlayerState extends State { currentPosition = ((state.inMilliseconds.toDouble() / maxPosition) * AudioPlayerWidget.wavesCount) .round(); + thisPosition = state.inMilliseconds.toDouble(); }); + if (thisPosition == maxPosition) { + audioPlayer.stop(); + audioPlayer.seek(null); + } + }); onDurationChanged ??= audioPlayer.durationStream.listen((max) { if (max == null || max == Duration.zero) return;