fix(player): restore playback position reliably

This commit is contained in:
zarzet
2026-07-29 21:03:11 +07:00
parent 43a8d08851
commit 04a8700a65
6 changed files with 213 additions and 53 deletions
+19 -2
View File
@@ -28,6 +28,16 @@ final playbackPlayingProvider = Provider<bool>((ref) {
);
});
final playbackLoadingProvider = Provider<bool>((ref) {
return ref.watch(
playbackStateProvider.select((state) {
final processingState = state.value?.processingState;
return processingState == AudioProcessingState.loading ||
processingState == AudioProcessingState.buffering;
}),
);
});
final playQueueProvider = StreamProvider<List<MediaItem>>((ref) {
return musicPlayerQueueEvents();
});
@@ -89,10 +99,17 @@ class MusicPlayerController {
Future<void> previous() async => _handler?.skipToPrevious();
Future<void> togglePlayPause(bool isPlaying) async {
final handler = _handler;
if (handler == null) return;
final processingState = handler.playbackState.value.processingState;
if (processingState == AudioProcessingState.loading ||
processingState == AudioProcessingState.buffering) {
return;
}
if (isPlaying) {
await pause();
await handler.pause();
} else {
await play();
await handler.play();
}
}