Skip to content

call .cloneAndRemove().cloneAndInsert() on ShuffleOrder for moveMediaItems() in ExoPlayer #1932

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

Open
nift4 opened this issue Nov 30, 2024 · 0 comments

Comments

@nift4
Copy link

nift4 commented Nov 30, 2024

[REQUIRED] Use case description

I wrote a custom ShuffleOrder class with four major goals:

  1. when enabling shuffle in one specific item, it will be the first item in shuffled playlist so everything else plays afterwards
  2. when user presses "play next", it will play next even if shuffle is enabled (inserted items are shuffled among themselves and inserted after previous song from normal playlist in shuffle playlist)
  3. support saving and loading from disk
  4. sensible movement of media items

This mostly works fine with more or less hacky approaches for each of the desired features.
However, my custom shuffle order has no chance of reacting to moveMediaItems(): unlike set/add/remove methods, moveMediaItems does not clone and edit the shuffle order. Due to that, moving a playlist item from UI while shuffle is enabled acts unpredictably (the shuffled indices mapping will not change) while my implementation acts as expected by users (insertion point is after the previous item in shuffled list).

Proposed solution

Call shuffleOrder.cloneAndRemove().cloneAndInsert() inside ExoPlayerImpl when moveMediaItems() is called to inform the shuffle order of changes. This allows custom shuffle order implementations to react however they like while not impacting DefaultShuffleOrder (it's still random, just a bit differently random).

Alternatives considered

ForwardingPlayer that, when moveMediaItems() is called, extracts the current copy of the shuffle order using reflection, calling the clone methods and then setShuffleOrder() manually. This is fragile and causes ExoPlayer to reload timeline. However, it works as intended.

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

No branches or pull requests

2 participants