Package com.google.android.exoplayer2.testutil

## Class FakeTrackSelection

- java.lang.Object
- - com.google.android.exoplayer2.testutil.FakeTrackSelection

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

      public final class FakeTrackSelection
      extends Object
      implements ExoTrackSelection

  A fake `ExoTrackSelection` that only returns 1 fixed track, and allows querying the number of calls to its methods.

- - ### Nested Class Summary

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

      `ExoTrackSelection.Definition, ExoTrackSelection.Factory`

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

      `TrackSelection.Type`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `int` | `enableCount` |
    `boolean` | `isEnabled` |
    `int` | `releaseCount` |

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

      `TYPE_CUSTOM_BASE, TYPE_UNSET`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `FakeTrackSelection​(TrackGroup rendererTrackGroup)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `blacklist​(int index, long exclusionDurationMs)` | Attempts to exclude the track at the specified index in the selection, making it ineligible for selection by calls to `ExoTrackSelection.updateSelectedTrack(long, long, long, List, MediaChunkIterator[])` for the specified period of time.
    `void` | `disable()` | Disables this track selection.
    `void` | `enable()` | Enables the track selection.
    `int` | `evaluateQueueSize​(long playbackPositionUs, List<? extends MediaChunk> queue)` | Returns the number of chunks that should be retained in the queue.
    `Format` | `getFormat​(int index)` | Returns the format of the track at a given index in the selection.
    `int` | `getIndexInTrackGroup​(int index)` | Returns the index in the track group of the track at a given index in the selection.
    `Format` | `getSelectedFormat()` | Returns the `Format` of the individual selected track.
    `int` | `getSelectedIndex()` | Returns the index of the selected track.
    `int` | `getSelectedIndexInTrackGroup()` | Returns the index in the track group of the individual selected track.
    `Object` | `getSelectionData()` | Returns optional data associated with the current track selection.
    `@com.google.android.exoplayer2.C.SelectionReason int` | `getSelectionReason()` | Returns the reason for the current track selection.
    `TrackGroup` | `getTrackGroup()` | Returns the `TrackGroup` to which the selected tracks belong.
    `int` | `getType()` | Returns an integer specifying the type of the selection, or `TrackSelection.TYPE_UNSET` if not specified.
    `int` | `indexOf​(int indexInTrackGroup)` | Returns the index in the selection of the track with the specified index in the track group.
    `int` | `indexOf​(Format format)` | Returns the index in the selection of the track with the specified format.
    `boolean` | `isBlacklisted​(int index, long nowMs)` | Returns whether the track at the specified index in the selection is excluded.
    `int` | `length()` | Returns the number of tracks in the selection.
    `void` | `onPlaybackSpeed​(float playbackSpeed)` | Called to notify the selection of the current playback speed.
    `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 java.lang.Object

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

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

      `onDiscontinuity, onPlayWhenReadyChanged, onRebuffer, shouldCancelChunkLoad`

- - ### Field Detail

    - #### enableCount

          public int enableCount

    - #### releaseCount

          public int releaseCount

    - #### isEnabled

          public boolean isEnabled

  - ### Constructor Detail

    - #### FakeTrackSelection

          public FakeTrackSelection​(TrackGroup rendererTrackGroup)

  - ### Method Detail

    - #### getType

          public int getType()

      Description copied from interface: `TrackSelection`
      Returns an integer specifying the type of the selection, or `TrackSelection.TYPE_UNSET` if not specified.

      Track selection types are specific to individual applications, but should be defined starting from `TrackSelection.TYPE_CUSTOM_BASE` to ensure they don't conflict with any types that may be added to the library in the future.

      Specified by:
        `getType` in interface `TrackSelection`

    - #### getTrackGroup

          public TrackGroup getTrackGroup()

      Description copied from interface: `TrackSelection`
      Returns the `TrackGroup` to which the selected tracks belong.
      Specified by:
        `getTrackGroup` in interface `TrackSelection`

    - #### length

          public int length()

      Description copied from interface: `TrackSelection`
      Returns the number of tracks in the selection.
      Specified by:
        `length` in interface `TrackSelection`

    - #### getFormat

          public Format getFormat​(int index)

      Description copied from interface: `TrackSelection`
      Returns the format of the track at a given index in the selection.
      Specified by:
        `getFormat` in interface `TrackSelection`
      Parameters:
        `index` - The index in the selection.
      Returns:
        The format of the selected track.

    - #### getIndexInTrackGroup

          public int getIndexInTrackGroup​(int index)

      Description copied from interface: `TrackSelection`
      Returns the index in the track group of the track at a given index in the selection.
      Specified by:
        `getIndexInTrackGroup` in interface `TrackSelection`
      Parameters:
        `index` - The index in the selection.
      Returns:
        The index of the selected track.

    - #### indexOf

          public int indexOf​(Format format)

      Description copied from interface: `TrackSelection`
      Returns the index in the selection of the track with the specified format. The format is located by identity so, for example, `selection.indexOf(selection.getFormat(index)) == index` even if multiple selected tracks have formats that contain the same values.
      Specified by:
        `indexOf` in interface `TrackSelection`
      Parameters:
        `format` - The format.
      Returns:
        The index in the selection, or `C.INDEX_UNSET` if the track with the specified format is not part of the selection.

    - #### indexOf

          public int indexOf​(int indexInTrackGroup)

      Description copied from interface: `TrackSelection`
      Returns the index in the selection of the track with the specified index in the track group.
      Specified by:
        `indexOf` in interface `TrackSelection`
      Parameters:
        `indexInTrackGroup` - The index in the track group.
      Returns:
        The index in the selection, or `C.INDEX_UNSET` if the track with the specified index is not part of the selection.

    - #### enable

          public void enable()

      Description copied from interface: `ExoTrackSelection`
      Enables the track selection. Dynamic changes via `ExoTrackSelection.updateSelectedTrack(long, long, long, List, MediaChunkIterator[])`, `ExoTrackSelection.evaluateQueueSize(long, List)` or `ExoTrackSelection.shouldCancelChunkLoad(long, Chunk, List)` will only happen after this call.

      This method may not be called when the track selection is already enabled.

      Specified by:
        `enable` in interface `ExoTrackSelection`

    - #### disable

          public void disable()

      Description copied from interface: `ExoTrackSelection`
      Disables this track selection. No further dynamic changes via `ExoTrackSelection.updateSelectedTrack(long, long, long, List, MediaChunkIterator[])`, `ExoTrackSelection.evaluateQueueSize(long, List)` or `ExoTrackSelection.shouldCancelChunkLoad(long, Chunk, List)` will happen after this call.

      This method may only be called when the track selection is already enabled.

      Specified by:
        `disable` in interface `ExoTrackSelection`

    - #### getSelectedFormat

          public Format getSelectedFormat()

      Description copied from interface: `ExoTrackSelection`
      Returns the `Format` of the individual selected track.
      Specified by:
        `getSelectedFormat` in interface `ExoTrackSelection`

    - #### getSelectedIndexInTrackGroup

          public int getSelectedIndexInTrackGroup()

      Description copied from interface: `ExoTrackSelection`
      Returns the index in the track group of the individual selected track.
      Specified by:
        `getSelectedIndexInTrackGroup` in interface `ExoTrackSelection`

    - #### getSelectedIndex

          public int getSelectedIndex()

      Description copied from interface: `ExoTrackSelection`
      Returns the index of the selected track.
      Specified by:
        `getSelectedIndex` in interface `ExoTrackSelection`

    - #### getSelectionReason

          public @com.google.android.exoplayer2.C.SelectionReason int getSelectionReason()

      Description copied from interface: `ExoTrackSelection`
      Returns the reason for the current track selection.
      Specified by:
        `getSelectionReason` in interface `ExoTrackSelection`

    - #### getSelectionData

          @Nullable
          public Object getSelectionData()

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

    - #### onPlaybackSpeed

          public void onPlaybackSpeed​(float playbackSpeed)

      Description copied from interface: `ExoTrackSelection`
      Called to notify the selection of the current playback speed. The playback speed may affect adaptive track selection.
      Specified by:
        `onPlaybackSpeed` in interface `ExoTrackSelection`
      Parameters:
        `playbackSpeed` - The factor by which playback is sped up.

    - #### 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.

      Specified by:
        `updateSelectedTrack` in interface `ExoTrackSelection`
      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.

    - #### evaluateQueueSize

          public int evaluateQueueSize​(long playbackPositionUs,
                                       List<? extends MediaChunk> queue)

      Description copied from interface: `ExoTrackSelection`
      Returns the number of chunks that should be retained in the queue.

      May be called by sources that load media in discrete `MediaChunks` and support discarding of buffered chunks.

      To avoid excessive re-buffering, implementations should normally return the size of the queue. An example of a case where a smaller value may be returned is if network conditions have improved dramatically, allowing chunks to be discarded and re-buffered in a track of significantly higher quality. Discarding chunks may allow faster switching to a higher quality track in this case.

      Note that even if the source supports discarding of buffered chunks, the actual number of discarded chunks is not guaranteed. The source will call `ExoTrackSelection.updateSelectedTrack(long, long, long, List, MediaChunkIterator[])` with the updated queue of chunks before loading a new chunk to allow switching to another quality.

      This method will only be called when the selection is enabled and none of the `MediaChunks` in the queue are currently loading.

      Specified by:
        `evaluateQueueSize` in interface `ExoTrackSelection`
      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.
        `queue` - The queue of buffered `MediaChunks`. Must not be modified.
      Returns:
        The number of chunks to retain in the queue.

    - #### blacklist

          public boolean blacklist​(int index,
                                   long exclusionDurationMs)

      Description copied from interface: `ExoTrackSelection`
      Attempts to exclude the track at the specified index in the selection, making it ineligible for selection by calls to `ExoTrackSelection.updateSelectedTrack(long, long, long, List, MediaChunkIterator[])` for the specified period of time.

      Exclusion will fail if all other tracks are currently excluded. If excluding the currently selected track, note that it will remain selected until the next call to `ExoTrackSelection.updateSelectedTrack(long, long, long, List, MediaChunkIterator[])`.

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

      Specified by:
        `blacklist` in interface `ExoTrackSelection`
      Parameters:
        `index` - The index of the track in the selection.
        `exclusionDurationMs` - The duration of time for which the track should be excluded, in milliseconds.
      Returns:
        Whether exclusion was successful.

    - #### isBlacklisted

          public boolean isBlacklisted​(int index,
                                       long nowMs)

      Description copied from interface: `ExoTrackSelection`
      Returns whether the track at the specified index in the selection is excluded.
      Specified by:
        `isBlacklisted` in interface `ExoTrackSelection`
      Parameters:
        `index` - The index of the track in the selection.
        `nowMs` - The current time in the timebase of `SystemClock.elapsedRealtime()`.