Skip to content

Commit

Permalink
fix: rewind breaks track progress bar (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Sep 10, 2023
1 parent d3e1cef commit e321743
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/hooks/use_progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e321743

Please sign in to comment.