Skip to content

Commit

Permalink
fix: no progress update when track changed
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jun 10, 2023
1 parent 8be67d0 commit 6ae8964
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/hooks/use_progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:spotube/services/audio_player/audio_player.dart';
Duration duration,
double bufferProgress
}) useProgress(WidgetRef ref) {
ref.watch(ProxyPlaylistNotifier.provider);
final playlist = ref.watch(ProxyPlaylistNotifier.provider);

final bufferProgress =
useStream(audioPlayer.bufferedPositionStream).data?.inSeconds ?? 0;
Expand All @@ -30,9 +30,11 @@ import 'package:spotube/services/audio_player/audio_player.dart';
useEffect(() {
// 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;
return audioPlayer.positionStream.listen((event) {
if (event.inMilliseconds - lastPosition.inMilliseconds < 1000) return;
if (event.inMilliseconds > 1000 &&
event.inMilliseconds - lastPosition.inMilliseconds < 1000) return;
lastPosition = event;
position.value = event;
}).cancel;
Expand Down

0 comments on commit 6ae8964

Please sign in to comment.