androidx / androidx/media

Enhanced shuffle utils (e.g. for continuously shuffled playback)

Open
#2,334 2 comments 0 reactions 1 assignee View on GitHub

@tonihei is already working on this.

Since Apr 17, 2025.

enhancement
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

I find the implementation of random playback in media3 very strange.
Firstly, we must set shuffleModeEnabled=true
If the repetition mode is Player.REPEAT_MODE_OFF, After playing the list once, it will stop.
If the repetition mode is Player.REPEAT_MODE_ALL, So the list will be played repeatedly, even though it's "random".

People's preference is usually for an uninterrupted experience of random playback, as a playlist may require listening multiple times At present, the implementation of media3 is to create a random playback order and then use it repeatedly without changing this order.

I have tried many methods, but none of them have been effective. For example:

  1. use mode Player.REPEAT_MODE_OFF, Then I also need to maintain a random order list myself, set a new order when Player.STATE_ENDED is triggered at the end of playback, and restart the player.

One downside of this is that it may appear to be coherent, but in reality, if a session is connected, the buttons for the previous and next songs will not be available when playing the first or last song, because the playback mode itself is not looping, but I artificially constructed it as a loop.

  1. I tried calling setShuffleOrder, but it would interrupt the player's playback status.

For example, I have a playlist [1, 2, 3, 4], and the current random order is [3, 1, 4, 2].
Monitor media switching in onMediaItemTransition.

If I determine that nextMediaItemIndex is the starting point of the playback I recorded, then I will regenerate a new random order. When the last media 2 is played, setShuffleOrder will reconstruct the entire player, directly interrupting the playback of 2 and playing it in the new order. In this way, I only played [3, 1, 4] instead of [3, 1, 4, 2] in a loop.

If I determine that currentMediaItemIndex is the starting point I have recorded, although there is no problem with regenerating the order, it means that the media 2 has been played twice or there may be a break interval At this point, I am playing [3, 1, 4, 2, 2] instead of [3, 1, 4, 2].

Hope
What I hope is that media3 can provide an internal setting to avoid me writing these obscure and useless codes. I hope that after enabling random playback, when the list reaches the last track (referring to random order), the random order can be automatically refreshed and seamlessly switched.

For the above example, a possible order is as follows:
[3, 1, 4, 2] (switch, The next one is definitely not 2) -> [3, 1, 4, 2] -> ....

Although I have looked at some of the internal implementation code of media3, if it is my ignorance that did not use media3 correctly, please tell me the correct method. Thank you!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.