Implement 'unshuffle' functionality #634
Replies: 19 comments
-
Indeed. We need to look up the context for this. In cases where this is no context, I'm not sure what you do. |
Beta Was this translation helpful? Give feedback.
-
The other solution might be to take a random index for selecting the song, i.e. don't shuffle the list of tracks, but rather create a So for a A bit more complicated, but means that one doesn't need to work out how to retrieve ordered lists when no context is provided. |
Beta Was this translation helpful? Give feedback.
-
If we can keep track of the seed, the Fisher–Yates algorithm (that you describe here?) might be a way to shuffle - unshuffle lists with small overheads? |
Beta Was this translation helpful? Give feedback.
-
Not sure it's an official algorithm, just made it up to be what I thought a sensible way to do things. How you shuffle the integer array initially is up to you |
Beta Was this translation helpful? Give feedback.
-
I think when I was experimenting the official app just didn't let you unshuffle. However, most of the time you do have a context so you just don't notice. That to me seems fine, the less complicated the better. But maybe its changed, someone should investigate. |
Beta Was this translation helpful? Give feedback.
-
What is |
Beta Was this translation helpful? Give feedback.
-
Also, Spotify uses Fisher-Yates, so for the sake of consistency, we should probably aim for that. |
Beta Was this translation helpful? Give feedback.
-
Now this is interesting, Spotify filed a patent for a weighted playlist shuffling algorithm: https://patentimages.storage.googleapis.com/d2/65/e2/8d6d3df46e77da/US20170244770A1.pdf and the weights are included with the tracks in a playlist, when retrieved via a uri such as More food for thought, I don't think we need to implement the same level of complexity, something like fisher yates or a random shuffle and context retrieval should be plenty. |
Beta Was this translation helpful? Give feedback.
-
Agreed, we can just seed with a hash of the start time of librespot or something and Store that in memory. Shouldn't be too hard. |
Beta Was this translation helpful? Give feedback.
-
The problem with the non-context case is when some other client shuffles the tracks and sends them in an update, all you have is those tracks. You have no way to know how to unshuffle them. The other client may have shuffled a hundred time before librespot joined the connect session so it really has no idea of the shuffle history and the seed doesn't help.
Not letting you unshuffle tracks without a context. Or, rather, making it a no-op. |
Beta Was this translation helpful? Give feedback.
-
Have just experimented, Spotify is syncing shuffle state across clients. If you shuffle on one client, skip a song, connect from another client and take over listening, you can go back to the previous song. However, if you shuffle a playlist on |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I follow what you are saying here. The (shuffled) track list and current track index give you all the state you need to skip backwards. This is all already implemented in librespot, yes? |
Beta Was this translation helpful? Give feedback.
-
As in the shuffled track list is kept in sync between clients, and not just on the client locally |
Beta Was this translation helpful? Give feedback.
-
@sashahilton00 In fact, you have to communicate it for Spotify to display the queue. |
Beta Was this translation helpful? Give feedback.
-
Yes, exactly. That's how it all works already and that's what we support in the original shuffle/repeat/queue work. |
Beta Was this translation helpful? Give feedback.
-
sure, but that doesn't explain why you can skip back/forwards when the client that originally shuffled it is open, but when you move clients and close the previous, you lose the ability to skip back |
Beta Was this translation helpful? Give feedback.
-
it's a minor issue, i'm not bothered if we can't skip back after switching clients on a shuffled playlist, but just thought i'd note it. |
Beta Was this translation helpful? Give feedback.
-
I found the behaviour was inconsistent between phone and desktop clients. It might just be their buggy software. |
Beta Was this translation helpful? Give feedback.
-
I've looked at some captured packets and it looks like Spotify doesn't do much when you toggle shuffle, probably because he has already stored in memory a copy of the playlist. Anyway it does something:
Some of the metadata includes:
|
Beta Was this translation helpful? Give feedback.
-
Currently when one shuffles the songs, the local queue in librespot is shuffled. when shuffle is disabled, the queue is not unshuffled. We should retrieve the original playlist on unshuffle, and then replace queue will all tracks after the index of the one currently playing.
Beta Was this translation helpful? Give feedback.
All reactions