Skip to content

Fix missing server-side lyrics in Now Playing - #1406

Merged
formatBCE merged 3 commits into
music-assistant:mainfrom
G74v3Dw31137:fix/now-playing-lyrics
Nov 18, 2026
Merged

formatBCE merged 3 commits into
music-assistant:mainfrom
G74v3Dw31137:fix/now-playing-lyrics

Conversation

@G74v3Dw31137

@G74v3Dw31137 G74v3Dw31137 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1404

Is there anything about the code changes here that should be highlighted?

Previously, Now Playing only checked the track's embedded lyrics field. Lyrics provided by Music Assistant metadata providers (such as LRCLIB or Genius) were therefore unavailable, even when they were displayed correctly in the web interface.

This PR adds support for fetching server-side lyrics through the existing metadata/get_track_lyrics API.

Key changes:

  • Introduces a shared lyrics repository for Now Playing, with embedded lyrics taking priority over fetched lyrics.
  • Fetches lyrics on demand when Now Playing is expanded.
  • Caches results and deduplicates concurrent requests to avoid unnecessary API calls.
  • Prevents stale responses from displaying lyrics for the wrong track.
  • Shares the resolved lyrics state between Now Playing and the lyrics dialog.
  • Adds tests for lyrics retrieval, caching, request deduplication, and track changes.

The implementation reuses the existing Music Assistant API and does not require any server-side changes.

Testing:

  • Android application builds successfully.
  • Automated tests pass.
  • Manually verified on a physical device running GrapheneOS, including tracks with lyrics supplied by metadata providers.

Are there any additional changes not related to the issue above?

No.

Before submitting this PR, make sure you have:

  • Given this PR a readable name that can be used in the app's changelog
  • Made sure checks pass by running ./gradlew detektAll testAndroidHostTest :androidApp:testDebug

started = entry == null || entry.state is DataState.Error
val access = (current.values.maxOfOrNull { it.access } ?: 0) + 1
// Returning to a cached track keeps it ahead of older requests that are still in flight.
current + (key to Entry(if (started) DataState.Loading() else entry!!.state, access))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do forced non-null cast in this repo.
I will post full comments a bit later.

@formatBCE formatBCE left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this!

A few points before merge:

Must fix

  1. entry!!.state in TrackLyricsRepository.load. The project bans !! in live code, and here it is avoidable: entry is never null on that path. Use entry?.state ?: DataState.Loading(), or carry the entry out of the started check.

Should fix

  1. The repository duplicates TranscriptRepository, with different wiring. TranscriptRepository is a Koin singleton in the app scope, because the item page and the player ask for the same episode. This PR builds TrackLyricsRepository inside HomeScreenViewModel on viewModelScope, which causes two problems:

    • It goes around DI. The project rule is that HomeScreenViewModel dependencies come from SharedModule.kt.
    • ItemDetailsViewModel still calls fetchTrackLyrics directly, so the track page and the player do not share a cache. TranscriptRepository exists to avoid exactly this.

    Suggestion: register it in Koin on the app scope and send the item page through it as well. Better still, make one LyricsRepository with load(track) and load(episode). The two classes differ only in the fetch call and the key.

  2. The access counter is more than this needs. maxOfOrNull + 1 on every load is a hand-built LRU. TranscriptRepository.appended() gets the same order by removing the key and adding it again, because a Kotlin Map keeps insertion order. Reusing that pattern removes the Entry wrapper.

  3. The error handling differs from the transcript path. This PR uses getOrThrow() with try/catch for cancellation, while TranscriptRepository uses Result.fold. Point 2 removes this difference if the classes merge, so align it either way.

Nits

  • The pager now collects trackLyrics for every composed page, not only the current one. That costs little, because it is a mapState, so this is fine.
  • .claude/architecture.md describes transcripts in the "Episode page" section but says nothing about Now Playing lyrics. Please add a line there, because the guidelines ask for it when a pattern changes.
  • The new case in MediaItemRepositoryLyricsTest tests fetchTrackLyrics, which this PR does not change. It does no harm, but it is out of scope.

With point 1 fixed and point 2 done (at least the Koin wiring), this is good to merge.

@G74v3Dw31137

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review!

I've pushed the requested changes:

  • Consolidated TrackLyricsRepository and TranscriptRepository into a single application-scoped LyricsRepository, registered through Koin.
  • Updated both Now Playing and Item Details to share cached results and in-flight requests.
  • Removed the !! assertion and custom LRU counter, using insertion-order cache eviction instead.
  • Aligned error handling with the existing transcript implementation and preserved cancellation behavior.
  • Updated .claude/architecture.md and removed the unrelated test.
  • Added regression tests for shared requests, cancellation, and cache eviction order.

All required checks pass: detektAll, testAndroidHostTest, and :androidApp:testDebug

The PR is ready for another review.

@formatBCE formatBCE left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is much better.

Three small things:

  • The .claude/architecture.md paragraph carries too much code detail. Please use ASD-STE100 style to conform the overall format.
  • The compare-and-set loop replaces an update { } that already worked.
  • The test files use different name styles.

@G74v3Dw31137

Copy link
Copy Markdown
Contributor Author

Thanks! I've addressed all three points. The changes are pushed and ready for another look.

@formatBCE formatBCE left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks for fixing!

@formatBCE
formatBCE merged commit 7f15c4c into music-assistant:main Nov 18, 2026
3 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.

Missing lyrics in now playing

2 participants