Skip to content

fix(cache): non-destructive backup restore, playback stability, and crash prevention - #62

Merged
d0x-dev merged 5 commits into
d0x-dev:mainfrom
drkvenom786:main
Sep 9, 2026
Merged

fix(cache): non-destructive backup restore, playback stability, and crash prevention#62
d0x-dev merged 5 commits into
d0x-dev:mainfrom
drkvenom786:main

Conversation

@drkvenom786

Copy link
Copy Markdown
Contributor

Overview

This PR delivers non-destructive cache backup & restore merging, playback stability enhancements, and crash prevention fixes.

Key Changes

  1. Non-Destructive Cache Restore:

    • Backup archives are now extracted into an isolated temporary folder before merging.
    • Preserves the device's active .uid file in exoplayer/ and download/ so ExoPlayer never treats existing chunk files as unindexed orphans on startup.
    • Maps restored chunk IDs dynamically using (maxExistingId + 1) for new tracks, or reuses the existing chunk ID if the track is already cached.
    • Restored and existing cache entries are integrated directly into the active ExoPlayerCacheIndex<activeHexUid> table, completely eliminating cache loss upon restoring.
    • Room database entries (songs, formats, artists) and restored_cache_ids.json are merged cleanly.
  2. Playback Stalling & Chunk Cache Fix:

    • Fixed cache verification in MusicService.kt and DownloadUtil.kt to only check the requested dataSpec.position. Previously checking position 0L caused downstream chunks (e.g. 512KB+) to be misidentified as cached, causing playback to pause or stop after 15–30 seconds.
  3. Crash Prevention (IllegalArgumentException: Out of range):

    • Wrapped the player passed to MediaLibrarySession in a ForwardingPlayer that safely clamps getBufferedPercentage() within [0, 100]. This eliminates the IllegalArgumentException: Out of range: -2524730863225 crash when buffering or playing edge-case tracks.
    • Ensured crossfade player swaps also use the safe session player wrapper.
  4. Listen Time Integrity:

    • Removed artificial playback Event logging during cache restoration, preventing listening time inflation.

@drkvenom786 drkvenom786 closed this Sep 9, 2026
@drkvenom786 drkvenom786 reopened this Sep 9, 2026
@d0x-dev
d0x-dev merged commit 15a3a16 into d0x-dev:main Sep 9, 2026
2 checks passed
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