4

I am creating a music player using exoplayer library. Everything works fine except the shuffle that is no behaving as I expect.

The problem that I have is the following:

Imagine that I have 5 songs:

song 1

song 2

song 3

song 4

song 5

and I am in the first one. Then I click on shuffle button and enable shuffled using exoPlayer.shuffleModeEnabled = true. Then now the order is the following:

song 4

song 2

song 5

song 1

song 3

As I was in song 1, after that it will go to song 3 and then it will finish without reproducing song 4, 2 and 5. The behavior that I spec is to reproduce all the songs in a random order. Is there any way to achieve that with exoplayer?

Iban Arriola
  • 2,526
  • 9
  • 41
  • 88

1 Answers1

0

You can implement your own ShuffleOrder to achieve this. One way to do this is to extend the DefaultShuffleOrder class and use a member field to store the starting index (in your example, it should be song 1). You should override the following methods:

getNextIndex(int index)
getPreviousIndex(int index)
getFirstIndex()
getLastIndex()

The idea is to make it a circular list. In your example, assume the shuffle order is 4, 2, 5, 1, 3 and 1 is currently being played, your getFirstIndex() should return 1, and getLastIndex() should return 5. For getNextIndex(int index) and getPreviousIndex(int index), do what it's supposed to do, but when you reach the head/tail just loop it around.

Then, when you want to activate shuffling, you do:

concatenatingMediaSource.setShuffleOrder(new MyShuffleOrder());
Yida Lin
  • 167
  • 2
  • 10