Skip to content

Commit

Permalink
fix audio not stopping and returning to start after finishing
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanniscoding authored Jul 16, 2023
1 parent a06b3e6 commit d22cc59
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/pages/chat/events/audio_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
String? statusText;
int currentPosition = 0;
double maxPosition = 0;
double thisPosition = 0;

MatrixFile? matrixFile;
File? audioFile;
Expand Down Expand Up @@ -118,7 +119,13 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
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;
Expand Down

0 comments on commit d22cc59

Please sign in to comment.