Skip to content
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

Shuffle replays songs randomly and queue resets to previous point #491

Closed
GrimJu opened this issue Aug 27, 2023 · 21 comments
Closed

Shuffle replays songs randomly and queue resets to previous point #491

GrimJu opened this issue Aug 27, 2023 · 21 comments

Comments

@GrimJu
Copy link

GrimJu commented Aug 27, 2023

Hi,
I just want to start by saying thank you so much for this amazing app. I've been using it for a few months now and it's been amazing.
I just encountered strange bugs when shuffling from the "all songs" section of the app.

After some time (on average 30 min but can occur after just 3-4 songs) the playback queue seems to reset to a previous point and replays songs in the order that they originally played. I believe this to be a differnet bug than #482
I've found no consistent way to trigger this (although skipping and especially going to the previous song seem to make it a lot worse).
After this bug occurs the first time the entire queue appers to be "cursed" and it will just keep happening more and more often.
Restarting the app does not help. You need to clear the queue and shuffle again to fix this.

I haven't found anything specific in the log but I've attached them anyway: finamp-logs.txt

I'd be very grateful if you manage to fix this. I'm very happy to provide any infos you need.

@Chaphasilor
Copy link
Collaborator

So the queue doesn't fully reset, it just goes back to any previous song? And yeah, the logs aren't of much help in this case. Better logging for playback events is in the works...

@jmshrv
Copy link
Owner

jmshrv commented Aug 29, 2023

Are you on Android or iOS? If Android, it might be related to #482

@GrimJu
Copy link
Author

GrimJu commented Aug 31, 2023

Hey,
I've found a consistent way to trigger the bug:

  1. Start shuffling from the "Songs" Tab
  2. skip a songs (or multiple)
  3. go to the last previous song
  4. wait until the song ends
    You'd expect to see the song that you originally pressed "go back" on. Instead a seemingly random song plays.

Just for context. I'm using a Oneplus 7 pro running lineageOS 20.

@GrimJu
Copy link
Author

GrimJu commented Sep 22, 2023

Any news on someone being able to reproduce this?

@kylekyleton
Copy link

Yes, this is happening to me also.

@Chaphasilor
Copy link
Collaborator

@GrimJu sorry, I didn't see that you provided a repro! Many thanks for that.
I've actually had this happen to me a few days ago but assumed I just broke something while working on #484.

I am able to reproduce this and will take a closer look...

@Chaphasilor
Copy link
Collaborator

Chaphasilor commented Oct 2, 2023

Got a few more questions, as this is a very strange bug:

  1. Does this behavior also happen after you skip forward?
  2. Does it happen after you seek within the track (moving the progress slider)?
  3. [You'll lose your Finamp settings with this one, maybe take screenshots before. Your server is unaffected] If you go to the android system settings for Finamp (e.g. by long-pressing the app icon, then tapping on "Info") and clear the whole storage for the app there (not just the cache), then force-stop it and finally launch it again, does this still happen?
  4. [Edit] Once this is happening, what happens if you turn shuffle off and then back on? Is the next track the one that is shown in the queue, or a different one?

I managed to get it working on one device (in some cases), but not the other. Now I'm really confused😅

@GrimJu
Copy link
Author

GrimJu commented Oct 2, 2023

Just retested all those

  1. Does this behavior also happen after you skip forward?

Yes

  1. Does it happen after you seek within the track (moving the progress slider)?

Yes

  1. If you go to the android system settings for Finamp (e.g. by long-pressing the app icon, then tapping on "Info") and clear the whole storage for the app there (not just the cache), then force-stop it and finally launch it again, does this still happen?

Did not fix any instance of the bug

  1. Once this is happening, what happens if you turn shuffle off and then back on? Is the next track the one that is shown in the queue, or a different one?

It's a different one

@CPU-Blanc
Copy link

Hello, just chiming in and reporting this is happening to me too. I shuffle from a downloaded playlist and it happens there, even while in "offline" mode.

@kylekyleton
Copy link

kylekyleton commented Dec 28, 2023

Still happening to me on 0.6.18

Actually, after thinking about it, I'm not so sure that this is the same issue:

It looks like the "shuffle tracks" button creates a playlist of tracks in a random order. If the player would just play this shuffled playlist sequentially, that would be a good enough shuffle for most people, I suspect.
However, what actually happens is that allowing a track to finish while in shuffle mode selects a random track in that shuffled list, effectively doing a double-shuffle.
Note that this doesn't appear to happen when you press the button to skip the current track -- this functions as you would expect, jumping to the next sequential item in the playlist.

I'm not familiar enough with this project (or android development more generally) to know where to even begin looking to see if this is what's actually happening, but I'm gonna have a look anyhow and see if I can figure out what's going on.

@kylekyleton
Copy link

kylekyleton commented Dec 28, 2023

Not familiar with git, excuse me if I get some terminology wrong. Hopefully you can still understand what I'm trying to say:

I've done some testing in the master checkout. I've managed to pinpoint the bit of code that affects this issue directly.
In lib/services/music_player_background_task.dart, line 397:

case AudioServiceShuffleMode.all:
          await _player.setShuffleModeEnabled(true);
          shuffleNextQueue = true;
          break;

becomes:

case AudioServiceShuffleMode.all:
          await _player.setShuffleModeEnabled(false);
          shuffleNextQueue = true;
          break;

This completely resolves the behavior I described in my previous post. This fix means enabling shuffled playback builds a shuffled queue that plays in order sequentially. If there's a reason to prefer a mode where the queue appears ordered but playback of that queue gets shuffled, we'll have to look elsewhere.
I didn't follow this trail any further -- I'm not sure what _player.setShuffleModeEnabled(true) is doing, but it appears to be the culprit. I also don't know if changing this breaks anything else.

Again, I'm not familiar with git; I don't know how you guys normally do things, so please forgive me for not just making a pull request or whatever.

Good luck friends. Keep up the good work.

@Chaphasilor
Copy link
Collaborator

I'll have to take a closer look, but it seems like the shuffled queue is simply not being shown in the correct order. setShuffleModeEnabled() will actively shuffle the queue by calculating a separate list of shuffleIndices. By using these new indices, the app could then map the shuffled order onto the actual tracks. It could be that this is not being done in the queue, so the tracks appear to be in-order unless manually shuffled once more.

In either case, this bug doesn't exist (afaik) in the redesign branch. I think I also pushed a fix for the shuffling behavior to the stable/main branch a while back that might be part of the next update, I'll have another look!

@Chaphasilor
Copy link
Collaborator

After playing around with it a bit, it doesn't seem like it is so trivial to fix. I'm not sure where exactly the wrong order is being produced. It's probably deep within the audio backend. I also tried out the fix suggested by @kylekyleton, but for me this just disables shuffle completely, aside from starting at a random song :(

I don't want to mess with this right now because I'd probably just make matters worse, so I'll invite everyone to try out the beta for the redesign (which includes a rewrite of the queuing system with more features) once that is released in the coming weeks!

@Chaphasilor
Copy link
Collaborator

@GrimJu @kylekyleton I've put some more work into queue management and the shuffle order and hope that this is now finally fixed!
Please try the redesign beta and report back if this is still an issue! You can check it out here: https://github.com/jmshrv/finamp/releases/tag/0.9.2-beta

I'll close this issue for now since it should be resolved.

@CPU-Blanc
Copy link

@Chaphasilor I've been running on the redesign beta for a few days now, and unfortunately the issue has not resolved for me.
The queue will still randomly jump back 10+ songs or so during shuffle.

@Chaphasilor Chaphasilor reopened this Mar 2, 2024
@Chaphasilor
Copy link
Collaborator

Ah, damn it. Could you provide logs please? :)

@CPU-Blanc
Copy link

Unfortunately I was driving at the time so I couldn't grab the logs. I'll try next time I come across it

@CPU-Blanc
Copy link

After more testing, I've not noticed this happening anymore.
Not sure if there was an update to the beta branch recently that fixed it? (I did notice the UI changed a little more)

@Chaphasilor
Copy link
Collaborator

@CPU-Blanc sorry for not responding, seems like I missed your message. Maybe you hadn't yet received the beta update, the Play Store can sometimes take a while to load the beta after signing up for it. There was no update with any playback changes until this week, with 0.9.4 and 0.9.5. These updates did add further improvements to playback and queueing, so if you could test again with 0.9.5 that would be great!

@CPU-Blanc
Copy link

@Chaphasilor Sorry for the late reply. I wondered if that might've been the case, though I did fully uninstall the app before joining the beta and re-installing. I'll blame the app store.

I've been using 0.9.5 quite extensively over the last few days and haven't noticed any issues at all with shuffle playback. On the non-beta branch I would've had issues by now. I think it's fairly safe to mark it as resolved 👍

@Chaphasilor
Copy link
Collaborator

Yeah, signing up for the beta can take 10-20 minutes. You'll know you're in when the release notes ("What's new") change to a different text.

That's awesome news! I'm really glad everything is in order (or rather shuffled? xD) now!
Let me know if you have any other issues :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

5 participants