Skip to content

Fix critical playback crashes, cache expiry bug, and improve lyrics caching#1869

Open
nakchwalabhi wants to merge 2 commits intoz-huang:devfrom
nakchwalabhi:InnerTune-Own
Open

Fix critical playback crashes, cache expiry bug, and improve lyrics caching#1869
nakchwalabhi wants to merge 2 commits intoz-huang:devfrom
nakchwalabhi:InnerTune-Own

Conversation

@nakchwalabhi
Copy link
Copy Markdown

🚀 Summary

This PR fixes multiple critical and medium-level issues affecting playback stability, caching, and performance in the app.


🔴 Critical Fixes

1. Stream URL Cache Expiry Bug

  • Fixed incorrect expiry logic for cached stream URLs
  • Previously, expiry time was stored as a relative value instead of absolute timestamp
  • This caused stale URLs to be reused, leading to playback failures (403 errors) after a few hours

✅ Fix:

  • Store expiry as: currentTimeMillis + expiresInSeconds
  • Validate using proper time comparison

2. Double unbindService() Crash

  • Fixed crash caused by calling unbindService() twice
  • onStop() already unbinds the service, so calling it again in onDestroy() caused:
    IllegalArgumentException: Service not registered

✅ Fix:

  • Removed duplicate unbind call in onDestroy()

3. NullPointerException in Stream Handling

  • Fixed unsafe force unwraps (!!) on nullable fields:
    • url
    • contentLength

✅ Fix:

  • Added proper null checks
  • Throw PlaybackException(ERROR_CODE_NO_STREAM) when URL is null
  • Skip DB operations when contentLength is null

🟡 Medium Fixes

4. Lyrics Not Cached

  • Lyrics fetched from network were not being cached

✅ Fix:

  • Added LRU cache storage after successful fetch

5. Inconsistent Cache Key in LyricsHelper

  • Different cache keys used in different methods (mediaId vs artist-title)
  • Resulted in cache misses

✅ Fix:

  • Standardized cache key to mediaId

6. MIME Type Parsing Crash

  • split("codecs=")[1] could throw IndexOutOfBoundsException

✅ Fix:

  • Replaced with safe parsing using getOrNull(1)
  • Added null checks before DB operations

🎯 Impact

  • 🚫 Eliminates playback crashes and service lifecycle crash
  • 🎧 Fixes long-session playback failures (stale stream URLs)
  • ⚡ Improves performance by enabling lyrics caching
  • 🧠 Makes code safer by removing unsafe null handling
  • 🛠 Improves overall stability and reliability

🧪 Testing

  • Verified playback works correctly after extended usage
  • Confirmed no crashes on service lifecycle events
  • Tested lyrics caching across multiple songs

📌 Notes

  • No breaking changes introduced
  • Existing architecture and behavior preserved
  • Changes are minimal and focused on stability and correctness

Copilot AI and others added 2 commits April 12, 2026 08:06
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