Package com.google.android.exoplayer2.trackselection

## Class RandomTrackSelection

- java.lang.Object
- - com.google.android.exoplayer2.trackselection.BaseTrackSelection
  - - com.google.android.exoplayer2.trackselection.RandomTrackSelection

- All Implemented Interfaces:
    `ExoTrackSelection`, `TrackSelection`

      public final class RandomTrackSelection
      extends BaseTrackSelection

  An `ExoTrackSelection` whose selected track is updated randomly.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `RandomTrackSelection.Factory` | Factory for `RandomTrackSelection` instances.

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.trackselection.ExoTrackSelection

      `ExoTrackSelection.Definition`

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.trackselection.TrackSelection

      `TrackSelection.Type`

  - ### Field Summary

    - ### Fields inherited from class com.google.android.exoplayer2.trackselection.BaseTrackSelection

      `group, length, tracks`

    - ### Fields inherited from interface com.google.android.exoplayer2.trackselection.TrackSelection

      `TYPE_CUSTOM_BASE, TYPE_UNSET`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `RandomTrackSelection​(TrackGroup group, int[] tracks, int type, Random random)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `getSelectedIndex()` | Returns the index of the selected track.
    `Object` | `getSelectionData()` | Returns optional data associated with the current track selection.
    `int` | `getSelectionReason()` | Returns the reason for the current track selection.
    `void` | `updateSelectedTrack​(long playbackPositionUs, long bufferedDurationUs, long availableDurationUs, List<? extends MediaChunk> queue, MediaChunkIterator[] mediaChunkIterators)` | Updates the selected track for sources that load media in discrete `MediaChunk`s.

    - ### Methods inherited from class com.google.android.exoplayer2.trackselection.BaseTrackSelection

      `blacklist, disable, enable, equals, evaluateQueueSize, getFormat, getIndexInTrackGroup, getSelectedFormat, getSelectedIndexInTrackGroup, getTrackGroup, getType, hashCode, indexOf, indexOf, isBlacklisted, length, onPlaybackSpeed`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.google.android.exoplayer2.trackselection.ExoTrackSelection

      `onDiscontinuity, onPlayWhenReadyChanged, onRebuffer, shouldCancelChunkLoad`

- - ### Constructor Detail

    - #### RandomTrackSelection

          public RandomTrackSelection​(TrackGroup group,
                                      int[] tracks,
                                      int type,
                                      Random random)

      Parameters:
        `group` - The `TrackGroup`. Must not be null.
        `tracks` - The indices of the selected tracks within the `TrackGroup`. Must not be null or empty. May be in any order.
        `random` - A source of random numbers.

  - ### Method Detail

    - #### updateSelectedTrack

          public void updateSelectedTrack​(long playbackPositionUs,
                                          long bufferedDurationUs,
                                          long availableDurationUs,
                                          List<? extends MediaChunk> queue,
                                          MediaChunkIterator[] mediaChunkIterators)

      Description copied from interface: `ExoTrackSelection`
      Updates the selected track for sources that load media in discrete `MediaChunk`s.

      This method will only be called when the selection is enabled.

      Parameters:
        `playbackPositionUs` - The current playback position in microseconds. If playback of the period to which this track selection belongs has not yet started, the value will be the starting position in the period minus the duration of any media in previous periods still to be played.
        `bufferedDurationUs` - The duration of media currently buffered from the current playback position, in microseconds. Note that the next load position can be calculated as `(playbackPositionUs + bufferedDurationUs)`.
        `availableDurationUs` - The duration of media available for buffering from the current playback position, in microseconds, or `C.TIME_UNSET` if media can be buffered to the end of the current period. Note that if not set to `C.TIME_UNSET`, the position up to which media is available for buffering can be calculated as `(playbackPositionUs + availableDurationUs)`.
        `queue` - The queue of already buffered `MediaChunk`s. Must not be modified.
        `mediaChunkIterators` - An array of `MediaChunkIterator`s providing information about the sequence of upcoming media chunks for each track in the selection. All iterators start from the media chunk which will be loaded next if the respective track is selected. Note that this information may not be available for all tracks, and so some iterators may be empty.

    - #### getSelectedIndex

          public int getSelectedIndex()

      Description copied from interface: `ExoTrackSelection`
      Returns the index of the selected track.

    - #### getSelectionReason

          public int getSelectionReason()

      Description copied from interface: `ExoTrackSelection`
      Returns the reason for the current track selection.

    - #### getSelectionData

          @Nullable
          public Object getSelectionData()

      Description copied from interface: `ExoTrackSelection`
      Returns optional data associated with the current track selection.