0

I have a playlist of tracks, I need to click on a track element to play it once, and not automatically skip to the next track. I tried to use ProcessingState.completed but it only fires when the last track in the playlist ends. Is there a solution to this?

UPD

It is very important that the current playlist index is preserved. Since the state of the player buttons changes on ProcessingState.completed, it is inconvenient for me to have this method called if I play one track from the playlist.

JM Apps
  • 150
  • 1
  • 7
  • Maybe this is the same as this existing question? https://stackoverflow.com/questions/73339177/flutter-with-just-audio-is-it-possible-to-create-a-playlist-that-doesnt-aut – Ryan Heise Aug 26 '22 at 02:36
  • @RyanHeise Unfortunately this option doesn't work for me. I need the tracks to switch automatically, but only when the user clicks on the play button in the player. And for one item from playlist, one track would be played. It is very important that the order of the index in the playlist is preserved. It seems to me that it would be a good solution to do this: `_player.seek(Duration.zero, index: index, hasNext: false)` where the user could decide for himself whether there would be a transition to the next track or not. Thanks – JM Apps Aug 26 '22 at 03:25
  • If you feel your question is different from that one, you need to edit it to make it different. As it's written, your question is still the same as the other question. – Ryan Heise Aug 26 '22 at 08:50
  • Does this answer your question? [Flutter: With \[just audio\], is it possible to create a playlist that doesn't automatically jump to the next audio when the current finishes?](https://stackoverflow.com/questions/73339177/flutter-with-just-audio-is-it-possible-to-create-a-playlist-that-doesnt-aut) – Ryan Heise Sep 01 '22 at 09:59
  • @RyanHeise This option solves the problem partially. The fact is that with such an implementation, the general index from the playlist is not the same. – JM Apps Sep 01 '22 at 12:20
  • This comments section describes conditions that are not mentioned in the original question. Can you please edit the original question before someone tries to answer the wrong question or label it as a duplicate? – Ryan Heise Sep 01 '22 at 13:01
  • Your question still seems incomplete because you did not mention that you want it switch tracks automatically like you said in your comment, so I'm not sure which way you want it. However, I will answer your question the way it is now written. – Ryan Heise Sep 02 '22 at 14:56

1 Answers1

0

just_audio's playlists will auto-advance by definition. Therefore, what you need to do is separate your app's state model from just_audio's state model.

Let's assume you have these items in your app's state model: A B C D E.

If you want to play item B only, then you don't want a just_audio playlist that looks like [ A, B, C, D, E ]. Rather, you want a playlist that looks like [ B ]. That is, play item B and nothing after it. When you're ready to play something else, edit the playlist accordingly, but don't let your app's own state depend on just_audio's playlist since your app and just_audio have different notions of what a playlist is.

Ryan Heise
  • 2,273
  • 5
  • 14