androidx / androidx/media

Allow adding MediaItems contiguously to a ShuffleOrder

Open
#955 1 comment 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Jan 9, 2024.

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

Description

Before filing a feature request:

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

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.