You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on my own shuffle implementation for a music player app. When the user press shuffle, I need to put the currently playing track at the top of the queue (first position). I could not find any solution for this using the ExoPlayer shuffle mode, so I decided to create my own solution by moving the MediaSource objects on the playlist.
Right now I'm saving a reference of ConcatenatingMediaSource as an attribute and using moveMediaSource to change the positions. I'm not calling prepare or seek before changing the positions.
Let's say that the currently playing index is 4. Then the user hits shuffle and I move the playing item to position 0 by using moveMediaSource. If the user hits next, I would expect the next index to be 1, because I moved the playing item to position 0. But what I'm seeing is that the next index is being reported as 5. Sometimes even another random index.
How I'm suppose to achieve this behavior? There is a way to reset the currently playing index (getCurrentWindowIndex())? Or should I implement this in a different way?
The text was updated successfully, but these errors were encountered:
Implementing your own shuffle order should ideally happen by providing your own ShuffleOrder implementation to the ConcatenatingMediaSource. Have a look at our default to see how this class can be implemented. However, there is one problem for your case: the shuffle order is supposed to be immutable and you can't just change the order depending on when the shuffle mode is enabled (this is needed for thread safety). Ideally, we should add a method to ConcatanatingMediaSource which lets you update the ShuffleOrder. I'll mark this issue as an enhancement to track this.
After we added this method, you should be able to do something like
concatenatingMediaSource.setShuffleOrder(
new CustomShuffleOrderStartingAtIndex(player.getCurrentWindowIndex()),
() -> player.setShuffleModeEnabled(true));
whenever a user turns on the shuffle mode in your UI.
Independent of that, you can of course move around the media sources yourself to implement shuffling. Note that this doesn't keep the original order to easily toggle between shuffle mode on and off. And it also doesn't support inserting / deleting element elements from both the original and shuffled order natively. And finally, you will get onTimelineChanged notifications for each single move operation, which may be annoying and is likely causing unnecessary UI update operations.
When calling concatenatingMediaSource.moveMediaSource(...), you send a command to the player to perform the update. Note that is an asynchronous process and you won't see the update reflected in the player state immediately. That's why player.getCurrentWindowIndex() is still 4 and player.getNextWindowIndex() is still 5 immediately after calling the move method. There are two ways to wait for the update to happen:
Use the optional last parameter of the moveMediaSource method to do something after the operation completed. E.g. concatenatingMediaSource.moveMediaSource(4, 0, () -> Log.d(TAG, player.getCurrentWindowIndex()) will log "0".
Manually wait for eventListener.onTimelineChanged event which will be issued after the player handled the move operation.
This allows to update the shuffle order after the ConcatenatingMediaSource
has been created. ShuffleOrder objects should be immutable to ensure thread
safety and thus there is no way to do this currently.
Issue:#4791
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=212443146
I'm working on my own shuffle implementation for a music player app. When the user press shuffle, I need to put the currently playing track at the top of the queue (first position). I could not find any solution for this using the ExoPlayer shuffle mode, so I decided to create my own solution by moving the MediaSource objects on the playlist.
Right now I'm saving a reference of ConcatenatingMediaSource as an attribute and using moveMediaSource to change the positions. I'm not calling prepare or seek before changing the positions.
Let's say that the currently playing index is 4. Then the user hits shuffle and I move the playing item to position 0 by using moveMediaSource. If the user hits next, I would expect the next index to be 1, because I moved the playing item to position 0. But what I'm seeing is that the next index is being reported as 5. Sometimes even another random index.
How I'm suppose to achieve this behavior? There is a way to reset the currently playing index (getCurrentWindowIndex())? Or should I implement this in a different way?
The text was updated successfully, but these errors were encountered: