# ShuffleOrder

# ShuffleOrder

Artifact:[androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3)  
[View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/source/ShuffleOrder.java+class:androidx.media3.exoplayer.source.ShuffleOrder)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/source/ShuffleOrder "View this page in Java")

<br />

```
@UnstableApi
interface ShuffleOrder
```

<br />

Known direct subclasses  
[FakeShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeShuffleOrder),[ShuffleOrder.DefaultShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder.DefaultShuffleOrder),[ShuffleOrder.UnshuffledShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder.UnshuffledShuffleOrder)  

|------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [FakeShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeShuffleOrder)                                             | Fake[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)which returns a reverse order.                  |
| [ShuffleOrder.DefaultShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder.DefaultShuffleOrder)       | The default[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)implementation for random shuffle order. |
| [ShuffleOrder.UnshuffledShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder.UnshuffledShuffleOrder) | A[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)implementation which does not shuffle.             |

*** ** * ** ***

Shuffled order of indices.

The shuffle order must be immutable to ensure thread safety.

The order must be consistent when traversed both[forwards](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#getNextIndex(int))and[backwards](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#getPreviousIndex(int)).

## Summary

|                                                                                                                                                                                                               ### Nested types                                                                                                                                                                                                                |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[ShuffleOrder.DefaultShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder.DefaultShuffleOrder)` : `[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder) The default[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)implementation for random shuffle order. |
| `class `[ShuffleOrder.UnshuffledShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder.UnshuffledShuffleOrder)` : `[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder) A[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)implementation which does not shuffle.       |

|                                              ### Public functions                                               |
|-----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)`!` | [cloneAndClear](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndClear())`()` Returns a copy of the shuffle order with all elements removed.                                                                                                                                                                                                                                                                                              |
| [ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)`!` | [cloneAndInsert](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndInsert(int,int))`(insertionIndex: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, insertionCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns a copy of the shuffle order with newly inserted elements.                                                                                      |
| [ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)`!` | [cloneAndMove](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndMove(int,int,int))`(indexFrom: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, indexToExclusive: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, newIndexFrom: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns a copy of the shuffle order to be used after a move. |
| [ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)`!` | [cloneAndRemove](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndRemove(int,int))`(indexFrom: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, indexToExclusive: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns a copy of the shuffle order with a range of elements removed.                                                                                     |
| [ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)`!` | [cloneAndSet](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndSet(int,int))`(insertionCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, startIndex: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns a copy of the shuffle order with all elements replaced.                                                                                                  |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                     | [getFirstIndex](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#getFirstIndex())`()` Returns the first index in the shuffle order, or[INDEX_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET())if the shuffle order is empty.                                                                                                                                                                          |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                     | [getLastIndex](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#getLastIndex())`()` Returns the last index in the shuffle order, or[INDEX_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET())if the shuffle order is empty.                                                                                                                                                                             |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                     | [getLength](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#getLength())`()` Returns length of shuffle order.                                                                                                                                                                                                                                                                                                                                    |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                     | [getNextIndex](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#getNextIndex(int))`(index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns the next index in the shuffle order.                                                                                                                                                                                                                           |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                     | [getPreviousIndex](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#getPreviousIndex(int))`(index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns the previous index in the shuffle order.                                                                                                                                                                                                               |

## Public functions

### cloneAndClear

```
fun cloneAndClear(): ShuffleOrder!
```

Returns a copy of the shuffle order with all elements removed.  

### cloneAndInsert

```
fun cloneAndInsert(insertionIndex: Int, insertionCount: Int): ShuffleOrder!
```

Returns a copy of the shuffle order with newly inserted elements.  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| `insertionIndex: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The index in the unshuffled order at which elements are inserted. |
| `insertionCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The number of elements inserted at`insertionIndex`.               |

|                                                     Returns                                                     |
|-----------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)`!` | A copy of this[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)with newly inserted elements. |

### cloneAndMove

```
fun cloneAndMove(indexFrom: Int, indexToExclusive: Int, newIndexFrom: Int): ShuffleOrder!
```

Returns a copy of the shuffle order to be used after a move.

The default implementation is a no-op. Custom implementation can choose to re-shuffle when items are moved.  

|                                           Parameters                                            |
|-------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `indexFrom: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)        | The starting index in the unshuffled order of the range to move, from before the move occurs.                                                 |
| `indexToExclusive: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The smallest index (must be greater or equal to`indexFrom`) that is not included in the range of elements moved, from before the move occurs. |
| `newIndexFrom: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | The starting index in the unshuffled order of the range to move, from after the move occurs.                                                  |

|                                                     Returns                                                     |
|-----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| [ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)`!` | A copy of this[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)with the elements moved. |

### cloneAndRemove

```
fun cloneAndRemove(indexFrom: Int, indexToExclusive: Int): ShuffleOrder!
```

Returns a copy of the shuffle order with a range of elements removed.  

|                                           Parameters                                            |
|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------|
| `indexFrom: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)        | The starting index in the unshuffled order of the range to remove.                    |
| `indexToExclusive: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The smallest index (must be greater or equal to`indexFrom`) that will not be removed. |

|                                                     Returns                                                     |
|-----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)`!` | A copy of this[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)without the elements in the removed range. |

### cloneAndSet

```
fun cloneAndSet(insertionCount: Int, startIndex: Int): ShuffleOrder!
```

Returns a copy of the shuffle order with all elements replaced.

The default implementation uses[cloneAndClear](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndClear())and[cloneAndInsert](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder#cloneAndInsert(int,int))to replace all elements in the shuffle order. Custom implementations can override this method if the first element in the shuffled order should be set to the one whose index in the unshuffled order is`startIndex`.  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `insertionCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The number of elements.                                                                                                                                                                                                                                                                                                                                                                       |
| `startIndex: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | The index of the new element in the unshuffled order that should be the first in the shuffled order or[INDEX_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET())if the the first element in the shuffled order is not specified. It should be ignored if the new list is empty, or if it is larger than the last index (inclusive) of the new list. |

|                                                     Returns                                                     |
|-----------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)`!` | A copy of this[ShuffleOrder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/ShuffleOrder)with the elements replaced. |

### getFirstIndex

```
fun getFirstIndex(): Int
```

Returns the first index in the shuffle order, or[INDEX_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET())if the shuffle order is empty.  

### getLastIndex

```
fun getLastIndex(): Int
```

Returns the last index in the shuffle order, or[INDEX_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET())if the shuffle order is empty.  

### getLength

```
fun getLength(): Int
```

Returns length of shuffle order.  

### getNextIndex

```
fun getNextIndex(index: Int): Int
```

Returns the next index in the shuffle order.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|-----------|
| `index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | An index. |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The index after`index`, or[INDEX_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET())if`index`is the last element. |

### getPreviousIndex

```
fun getPreviousIndex(index: Int): Int
```

Returns the previous index in the shuffle order.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|-----------|
| `index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | An index. |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The index before`index`, or[INDEX_UNSET](https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET())if`index`is the first element. |