-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
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:
- Play a track and open the player sheet
- Expand the queue sheet (drag up from bitrate area or tap queue icon)
- Long-press on any track in the queue to open the menu
- Select "Play Next"
- Observe that the queue list doesn't update
- 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