fix: no progress update when track changed

This commit is contained in:
Kingkor Roy Tirtho 2023-06-10 21:47:59 +06:00
parent 8be67d02c4
commit 6ae896441a

View File

@ -9,7 +9,7 @@ import 'package:spotube/services/audio_player/audio_player.dart';
Duration duration, Duration duration,
double bufferProgress double bufferProgress
}) useProgress(WidgetRef ref) { }) useProgress(WidgetRef ref) {
ref.watch(ProxyPlaylistNotifier.provider); final playlist = ref.watch(ProxyPlaylistNotifier.provider);
final bufferProgress = final bufferProgress =
useStream(audioPlayer.bufferedPositionStream).data?.inSeconds ?? 0; useStream(audioPlayer.bufferedPositionStream).data?.inSeconds ?? 0;
@ -30,9 +30,11 @@ import 'package:spotube/services/audio_player/audio_player.dart';
useEffect(() { useEffect(() {
// audioPlayer.positionStream is fired every 200ms and only 1s delay is // audioPlayer.positionStream is fired every 200ms and only 1s delay is
// enough. Thus only update the position if the difference is more than 1s // enough. Thus only update the position if the difference is more than 1s
// Reduces CPU usage
var lastPosition = position.value; var lastPosition = position.value;
return audioPlayer.positionStream.listen((event) { return audioPlayer.positionStream.listen((event) {
if (event.inMilliseconds - lastPosition.inMilliseconds < 1000) return; if (event.inMilliseconds > 1000 &&
event.inMilliseconds - lastPosition.inMilliseconds < 1000) return;
lastPosition = event; lastPosition = event;
position.value = event; position.value = event;
}).cancel; }).cancel;