Skip to content

Reordering does not work well when combined with shuffle #1042

@Chaphasilor

Description

@Chaphasilor

Which API doesn't behave as documented, and how does it misbehave?
Name here the specific methods or fields that are not behaving as documented, and explain clearly what is happening.

ConcatenatingAudioSource.move()

Moves an AudioSource from currentIndex to newIndex

The described behavior only works as long as AudioPlayer.shuffleModeEnabled is false. If this is not the case, the unshuffled indices will be moved around instead, causing the shuffled order to change randomly instead of reflecting the desired change.
As a side effect, this also means that after disabling shuffle, the unshuffled indices are different than before, which is not how playlists should work. The unshuffled indices should never change, unless specifically requested.

In case this method is meant to behave exactly like it does, another method would be needed that only affects shuffled indices. The current one does not, as can be seen from the implementation.

Minimal reproduction project
Provide a link here using one of two options:

  1. Fork this repository and modify the example to reproduce the bug, then provide a link here.
  2. If the unmodified official example already reproduces the bug, just write "The example".

https://github.com/Chaphasilor/audio_service/tree/shuffle-reorder-bug-repro

Only change was renaming the shuffle example to main.dart and adding more dummy items to the playlists.

To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:

  1. Run playlist example
  2. Check the playlist/queue. All tracks should be in order (1-6)
  3. Enable shuffle. All tracks after the current track are shuffled, as expected
  4. Drag-and-drop one of the tracks to a different position within the playlist/queue. The track will (most likely) not be reordered correctly. Instead, a seemingly random track will change position. Repeat multiple times to observe erratic and unpredictable behavior.
  5. Disable shuffle. The queue (probably) won't be in the correct order anymore, although it should be. After all, it's not shuffled anymore.

Error messages

If applicable, copy & paste error message here, within the triple quotes to preserve formatting.

Expected behavior
A clear and concise description of what you expected to happen.

  • When shuffle is off, ConcatenatingAudioSource.move() should update the unshuffled indices, i.e. change the actual order of the AudioSource's children
  • When shuffle is on, ConcatenatingAudioSource.move() should update the shuffled indices, i.e. only change the ShuffleOrder.indices and not update the order of the AudioSource's children at all.
  • After reordering tracks while shuffle was on and then turning shuffle off, the original, unshuffled order should be restored. While shuffle is on, it should not be possible to update the unshuffled indices / order of children by calling ConcatenatingAudioSource.move()
  • Alternatively, there could be two distinct methods, one for only moving the unshuffled indices, and one for moving the shuffled ones

Screenshots
If applicable, add screenshots to help explain your problem.

2023-08-10-19-23-27.mp4

Desktop (please complete the following information):

  • OS: Windows 10 22H2
  • Browser: n/a

Smartphone (please complete the following information):

  • Device: ASUS Zenfone 10
  • OS: Android 13 (Zen UI)

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.19045.3208], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc4)
    X Could not determine java version
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.1)    
[!] Android Studio (version 2022.2)
    X Unable to determine bundled Java version.
[!] Android Studio (version 2022.1)
    X Unable to determine bundled Java version.
[√] VS Code (version 1.80.2)
[√] Connected device (4 available)
[√] Network resources

! Doctor found issues in 3 categories.

Additional context
Add any other context about the problem here.

Source question on StackOverflow: https://stackoverflow.com/questions/76813773/how-to-change-the-shuffled-order-in-just-audio-without-affecting-the-original-or

I've also checkout out various open-source flutter apps that use just_audio, but they either don't support reordering at all, or it is broken in the way I described.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions