-
-
Notifications
You must be signed in to change notification settings - Fork 678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reordering does not work well when combined with shuffle #1042
Comments
@ryanheise are you able to reproduce this? :) |
Hi @Chaphasilor , shuffled indices is just a view of the actual indices, so enabling and disabling shuffle mode simply switches between a shuffled view of the indices, and the "actual" indices. This is intended to allow you to switch back and forth between the two, because the original sequence is still intact. If the user of your app wants to actually treat the shuffled order as if it is the actual order, and can be further mutated with |
I would like to keep the original order and the shuffled order available to switch back and forth. I was just under the impression that, while shuffle is active, the I already attempted to use a custom ShuffleOrder, but still have some hiccups with it. I'll see if I can get working the way I want it to. Does that mean that this behavior is intended, and you're not planning to change which indices |
Yes, this is the intended behaviour, but I believe your use case should be possible to implement on top of this. Although you would have to define your own intended behaviour for the target of a move. For example, if the user is in shuffle mode and drags an item from position [2] to [4] in the shuffle view, it is clear what [2] means. You can look up the shuffle indices to find WHICH item that actually refers to (e.g. this might point to item [7] in the original list). But then what does it mean to drag this to position [4] in the view? You would need to define that. What I know is that you want the shuffled position to be [4] at the destination, but I don't know what position you want this to be in the original list. But once you define this and you know what you want it to be, let's say you want it to end up at [4] in the original list as well, then what you want to do is call For me, it's a little hard to guess what your intended behaviour might be, because I could imagine different apps wanting to implement different shuffle order behaviour (hence why it is customisable). But do let me know if you run into limitations in the API. |
Thank you for the explanantion. As stated in the original Stack Overflow quesion, I simply want the shuffle order and original order to be completely separate, so if I move an item within the shuffle view, I just want to update the shuffle indices and nothing else. Turning shuffle back off should show the original, unmodified order. It seems like in my case I'd simply need to overwrite the |
OK, this is not a use case I had designed it for so I'm not sure if it will be perfectly convenient for you. But you can make your shuffle order implementation modal so that you can set it to a particular mode before its methods are invoked. For example, one of your situations is that you want to move an item in the shuffle order without affecting the original order. The correct way to affect the shuffle order is to always call So you might consider having something like: class MyShuffleOrder extends ... {
(int, int)? pendingMove;
} And if it's not null, the pending move indices will be used by your shuffle implementation to execute the shuffle move as opposed to doing a full randomised shuffle. That's probably going to work even if it's not a usage this API was designed for. |
Ah okay, thanks for the pointer! So what you're saying is the shuffle indices view is only refreshed when By the way, would you be interested in me contributing my shuffle order through a pull request? It might be useful to others trying to build advanced music apps :) |
Well, the view is refreshed in a few other places too, such as when you invoke methods on Since the solution is going to be a bit hacky, I'm not sure yet whether it is something that should be an official example, or anything like that, but if you share your implementation below, that will both help others who search for this page, and also help me to take a look at what you're doing and consider future API changes to make such use cases less hacky. |
@Chaphasilor Have you managed to implement the shuffle logic you wanted? If yes, can you please share your implementation? I'm struggling with this myself. |
I am facing same issue in Android auto and below is my code snippet let me know if any solution available ` @OverRide
}` |
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()
The described behavior only works as long as
AudioPlayer.shuffleModeEnabled
isfalse
. 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:
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:
Error messages
Expected behavior
A clear and concise description of what you expected to happen.
ConcatenatingAudioSource.move()
should update the unshuffled indices, i.e. change the actual order of theAudioSource
's childrenConcatenatingAudioSource.move()
should update the shuffled indices, i.e. only change theShuffleOrder.indices
and not update the order of theAudioSource
's children at all.ConcatenatingAudioSource.move()
Screenshots
If applicable, add screenshots to help explain your problem.
2023-08-10-19-23-27.mp4
Desktop (please complete the following information):
Smartphone (please complete the following information):
Flutter SDK version
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.
The text was updated successfully, but these errors were encountered: