From e3217436c9985b86c68dab93ea65ee414b32fb49 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sun, 10 Sep 2023 11:47:03 +0600 Subject: [PATCH] fix: rewind breaks track progress bar (#695) --- lib/hooks/use_progress.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/hooks/use_progress.dart b/lib/hooks/use_progress.dart index 62dccbced..15a979af7 100644 --- a/lib/hooks/use_progress.dart +++ b/lib/hooks/use_progress.dart @@ -40,14 +40,14 @@ import 'package:spotube/services/audio_player/audio_player.dart'; } }); + var lastPosition = position.value; + // audioPlayer.positionStream is fired every 200ms and only 1s delay is // enough. Thus only update the position if the difference is more than 1s // Reduces CPU usage - var lastPosition = position.value; - final positionSubscription = audioPlayer.positionStream.listen((event) { - if (event.inMilliseconds > 1000 && - event.inMilliseconds - lastPosition.inMilliseconds < 1000) return; + final diff = event.inMilliseconds - lastPosition.inMilliseconds; + if (event.inMilliseconds > 1000 && diff < 1000 && diff > 0) return; lastPosition = event; position.value = event;