Skip to content

Fix/player desync on lyrics update#237

Merged
theovilardo merged 2 commits intomasterfrom
fix/player-desync-on-lyrics-update
Oct 11, 2025
Merged

Fix/player desync on lyrics update#237
theovilardo merged 2 commits intomasterfrom
fix/player-desync-on-lyrics-update

Conversation

@theovilardo
Copy link
Copy Markdown
Owner

No description provided.

When lyrics were updated for the current song (either via online search, accepting a search result, or importing a file), the `PlayerViewModel` would only update the `Song` object instance within the `stablePlayerState`.

The corresponding `Song` object within the `playerUiState.currentPlaybackQueue` remained unchanged. This created a state inconsistency.

When the UI recomposed, `AlbumCarouselSection` would use the new `currentSong` object to find its index within the old `currentPlaybackQueue`. Because the object references did not match, `indexOf` would return -1 (coerced to 0), causing the carousel to reset to the first song. This also caused the progress bar and other UI elements to desynchronize.

This fix addresses the issue by ensuring that whenever a song's lyrics are updated, the change is propagated to both `stablePlayerState.currentSong` and the corresponding object in `playerUiState.currentPlaybackQueue`. This is done by finding the song's index, creating an updated `Song` object, and replacing the old instance in the queue, thus maintaining state consistency.
This commit refactors the `PlayerViewModel` to introduce a centralized private function, `updateSongInStates`. This function is now the single source of truth for updating a song's metadata, ensuring that both the `stablePlayerState` and the `playerUiState.currentPlaybackQueue` are updated atomically and consistently.

Previously, when lyrics were updated (via online search, accepting a result, or importing a file), the different functions updated the state inconsistently. This created a race condition where the `currentSong` object instance in `stablePlayerState` would be different from the instance in the `currentPlaybackQueue`. When the UI recomposed, it would fail to find the new song object in the old queue, causing it to default to the first item and desynchronizing the player UI (album art, progress bar, etc.).

By refactoring `fetchLyricsForCurrentSong`, `acceptLyricsSearchResultForCurrentSong`, and `importLyricsFromFile` to use the new unified update function, this commit resolves the bug and improves the robustness of the state management logic.
@theovilardo theovilardo merged commit 053532d into master Oct 11, 2025
@theovilardo theovilardo deleted the fix/player-desync-on-lyrics-update branch October 16, 2025 18:04
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.

1 participant