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
+2
View File
@@ -133,6 +133,8 @@ class _MainShellState extends ConsumerState<MainShell>
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed && _initialSafRepairComplete) {
unawaited(_repairSafAccessIfNeeded());
} else if (state == AppLifecycleState.paused) {
unawaited(persistCurrentPlaybackSession());
}
}
+10 -2
View File
@@ -1005,6 +1005,7 @@ class _PlaybackControls extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final position = ref.watch(playbackPositionProvider);
final isPlaying = ref.watch(playbackPlayingProvider);
final isLoading = ref.watch(playbackLoadingProvider);
final shuffleOn = ref.watch(
playbackStateProvider.select(
(s) => s.value?.shuffleMode == AudioServiceShuffleMode.all,
@@ -1116,8 +1117,15 @@ class _PlaybackControls extends ConsumerWidget {
iconSize: 44,
padding: const EdgeInsets.all(12),
color: colorScheme.onPrimary,
icon: Icon(isPlaying ? Icons.pause : Icons.play_arrow),
onPressed: () => controller.togglePlayPause(isPlaying),
icon: isLoading
? const SizedBox.square(
dimension: 32,
child: CircularProgressIndicator(strokeWidth: 3),
)
: Icon(isPlaying ? Icons.pause : Icons.play_arrow),
onPressed: isLoading
? null
: () => controller.togglePlayPause(isPlaying),
),
),
const SizedBox(width: 20),