Skip to content

feat:gives persistent music playback/continue playing - #316

Merged
ajisth69 merged 1 commit into
Clash-Projects:mainfrom
Aadit-A:feat/continue-playing
Oct 13, 2026
Merged

ajisth69 merged 1 commit into
Clash-Projects:mainfrom
Aadit-A:feat/continue-playing

Conversation

@Aadit-A

@Aadit-A Aadit-A commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

This PR resolves an issue where the Continue Playing song, playback position, and upcoming queue were reset/lost after pausing playback, minimizing LastWave, and swiping the app away from Recents (or when Android reclaimed the background process).

When playback was paused and the user swiped LastWave away from Recents:
1.
MusicPlaybackService.onTaskRemoved() called musicPlayer.stopAndClear(clearSession = false).
2.
Inside stopAndClear(), player.clearMediaItems() caused ExoPlayer to dispatch an asynchronous onEvents callback on the Main thread.
3.
ExoPlayer's listener called refresh(player), which observed an empty timeline, set _state.value to an empty MusicPlayerState(), and called persistPlaybackSession().
4.
persistPlaybackSession() checked sourceQueue.isEmpty(), evaluated to true, and called clearPersistedPlaybackSession(), erasing PLAYBACK_SESSION_KEY from lastwave_playback_session SharedPreferences.
5.
Upon relaunch, restorePlaybackSession() found no saved session in SharedPreferences, causing the Continue Playing section and upcoming queue to start completely empty.

What Was Changed & How It Works-
•
Non-Destructive Empty Queue Handling: Updated persistPlaybackSession() in  MusicPlayer.kt to return early (if (sourceQueue.isEmpty()) return) when the in-memory queue is empty, rather than deleting the persisted session from disk.
•
Preserved Intentional Session Wiping: Session deletion on disk remains an explicit operation that occurs only when the user intentionally stops or clears playback (stopAndClear(clearSession = true)), closes the player, or when corrupt session JSON is encountered. Teardown transitions and empty ExoPlayer timelines no longer wipe disk storage.
•
Immediate Pause Persistence: Added a persistPlaybackSession() call inside MusicPlayer.pause() so the exact active track, playback position (positionMs), queue order, current index, shuffle, and repeat modes are saved to disk on Dispatchers.IO the instant playback is paused.
•
Non-Blocking Eager State Restoration: Upon relaunch, restorePlaybackSession() reads the saved session from SharedPreferences, restores _state.value immediately for UI rendering (Continue Playing / Mini Player), and lazily hydrates ExoPlayer in paused mode without blocking app startup.

Verification & Testing
•
Unit Tests: Executed .\gradlew.bat :app:testDebugUnitTest — All 350 unit tests passed.
•
Compilation: Executed .\gradlew.bat :app:compileDebugKotlin — BUILD SUCCESSFUL.
•
APK Build: Executed .\gradlew.bat assembleDebug — BUILD SUCCESSFUL.

@ajisth69
ajisth69 merged commit fec177b into Clash-Projects:main Oct 13, 2026
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.

2 participants