Skip to content

Queue UI doesn't refresh when adding track to Play Next while queue sheet is open #103

@Ericgacoki

Description

@Ericgacoki

Issue: Queue sheet UI does not update when adding track via "Play Next"


Description:

When the queue sheet (Now Playing list) is open and a user adds a track via "Play Next" from the track menu, the UI does not update to reflect the new queue state. The list remains stale until the user closes and reopens the queue sheet.

This causes an IndexOutOfBoundsException when interacting with the stale UI because the indices no longer match the actual queue:

java.lang.IndexOutOfBoundsException: Index n, size n
Process: com.android.swingmusic.debug, PID: 31267


Steps to Reproduce:

  1. Play a track and open the player sheet
  2. Expand the queue sheet (drag up from bitrate area or tap queue icon)
  3. Long-press on any track in the queue to open the menu
  4. Select "Play Next"
  5. Observe that the queue list doesn't update
  6. Try interacting with the list → crash may occur

Expected Behavior:
The queue list should immediately update to show the newly inserted track at the correct position.


Actual Behavior:
The queue list remains unchanged until the sheet is closed and reopened.


Root Cause Analysis:

In MediaControllerViewModel.kt, the queue state is updated with the same mutable list reference:

// addToPlayNextInQueue() - line ~387
targetQueue.add(insertIndex, playNextTrack)
_playerUiState.value = _playerUiState.value.copy(queue = targetQueue)

Since targetQueue is the same reference as workingQueue or shuffledQueue, Compose's equality check may not detect the change, preventing recomposition.


Potential Fix:

Create a new list instance when updating the state:

targetQueue.add(insertIndex, playNextTrack)
_playerUiState.value = _playerUiState.value.copy(queue = targetQueue.toList())

This applies to both addToPlayNextInQueue() and addToPlayingQueue() functions.

Note: Initial testing of this fix didn't resolve the issue, suggesting there may be additional factors involved (possibly related to how the queue sheet observes state changes or key stability in the LazyColumn).


Files Involved:

  • feature/player/src/main/java/com/android/swingmusic/player/presentation/viewmodel/MediaControllerViewModel.kt
  • feature/player/src/main/java/com/android/swingmusic/player/presentation/screen/AnimatedPlayerSheet.kt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions