Allow adding MediaItems contiguously to a ShuffleOrder
@marcbaechinger is already working on this.
Since Jan 9, 2024.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Before filing a feature request:
- Search existing open issues, specifically with the label ‘enhancement’:
https://github.com/androidx/media/labels/enhancement - For ExoPlayer-related feature requests, please also check for existing feature
requests on the ExoPlayer tracker:
https://github.com/google/ExoPlayer/labels/enhancement - Search existing pull requests:
- On this tracker: https://github.com/androidx/media/pulls,
- On the ExoPlayer tracker: https://github.com/google/ExoPlayer/pulls
When filing a feature request:
Replace the content in the sections below.
[REQUIRED] Use case description
My users expect to add a list of items to a queue, and have them show up in the queue in the exact order as they were in the list. Currently though, DefaultShuffleOrder seemingly disperses inserted MediaItems at random.
As a result, when a user adds items to the queue, instead getting:
v - User inserted these and expects them to appear here
Song 1 [Song 2, Song 3] Song 4 Song 5
They instead get:
v ?!?!?! v ?!?!?!!
[Song 2] Song 1 Song 4 [Song 3] Song 5
This is extremely user-unfriendly.
Proposed solution
cloneAndInsert's default implementation should then be changed to one that inserts the items contiguously at the insertion point, like this implementation I've made:
override fun cloneAndInsert(insertionIndex: Int, insertionCount: Int): ShuffleOrder {
if (shuffled.isEmpty()) {
return BetterShuffleOrder(insertionCount)
}
val newShuffled = IntArray(shuffled.size + insertionCount)
val pivot = indexInShuffled[insertionIndex]
for (i in shuffled.indices) {
var currentIndex = shuffled[i]
if (currentIndex > insertionIndex) {
currentIndex += insertionCount
}
if (i <= pivot) {
newShuffled[i] = currentIndex
} else if (i > pivot) {
newShuffled[i + insertionCount] = currentIndex
}
}
for (i in 0 until insertionCount) {
newShuffled[pivot + i + 1] = insertionIndex + i + 1
}
return BetterShuffleOrder(newShuffled)
}
There's likely some other internal changes that need to be made to accommodate this, see below:
Alternatives considered
I can implement this myself and use my own ShuffleOrder, but it's somewhat finicky to implement since ExoPlayer assumes the default implementation. More or less, it seems like replacing MediaItems and adding new MediaItems both call cloneAndInsert, so the method probably needs to be split depending on those cases for this to work.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.