Skip to content

Fix player state and cached track lost when task removed with nothing… - #54

Merged
ajisth69 merged 1 commit into
Clash-Projects:mainfrom
clonion:RealCFixed
Sep 10, 2026
Merged

Fix player state and cached track lost when task removed with nothing…#54
ajisth69 merged 1 commit into
Clash-Projects:mainfrom
clonion:RealCFixed

Conversation

@clonion

@clonion clonion commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Fix: Player state and cached track lost when task removed with nothing playing

Problem

MusicPlaybackService.onTaskRemoved() unconditionally called musicPlayer.stopAndClear() whenever the app's task left Recents — even when nothing was playing. stopAndClear() wipes both the in-memory player state and the persisted session in SharedPreferences (clearPersistedPlaybackSession()), so the next app launch had nothing to restore: the player appeared closed and the last track wasn't cached, regardless of battery-optimization settings.

Fix

  1. Skip the stop entirely when something is actively playing, so playback isn't killed just because the task left Recents.
  2. Give stopAndClear() an optional clearSession parameter (default true, unchanged for every other call site) so the paused/idle case can stop the service without deleting the persisted session — leaving it restorable on the next launch.

Files changed

  • app/src/main/java/com/lastwave/app/playback/MusicPlaybackService.kt
  • app/src/main/java/com/lastwave/app/playback/MusicPlayer.kt
  • CHANGELOG.md

Testing

  • Loaded a track, paused it, swiped the app from Recents, reopened — track/queue now restores correctly.
  • Confirmed active playback continues uninterrupted when the app is swiped from Recents.
  • Verified other stopAndClear() call sites (explicit stop button, notification stop action, media session onStop) are unaffected and still clear the session as before.

@ajisth69
ajisth69 merged commit 6355037 into Clash-Projects:main Sep 10, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants