Package com.google.android.exoplayer2.trackselection

## Class DefaultTrackSelector

- java.lang.Object
- - com.google.android.exoplayer2.trackselection.TrackSelector
  - - com.google.android.exoplayer2.trackselection.MappingTrackSelector
    - - com.google.android.exoplayer2.trackselection.DefaultTrackSelector

- Direct Known Subclasses:
    `FakeTrackSelector`

      public class DefaultTrackSelector
      extends MappingTrackSelector

  A default `TrackSelector` suitable for most use cases.

  ## Modifying parameters

  Track selection parameters should be modified by obtaining a `TrackSelectionParameters.Builder` initialized with the current `TrackSelectionParameters` from the player. The desired modifications can be made on the builder, and the resulting `TrackSelectionParameters` can then be built and set on the player:

       player.setTrackSelectionParameters(
           player.getTrackSelectionParameters()
               .buildUpon()
               .setMaxVideoSizeSd()
               .setPreferredAudioLanguage("de")
               .build());

  Some specialized parameters are only available in the extended `DefaultTrackSelector.Parameters` class, which can be retrieved and modified in a similar way by calling methods directly on this class:

       defaultTrackSelector.setParameters(
           defaultTrackSelector.getParameters()
               .buildUpon()
               .setTunnelingEnabled(true)
               .build());

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `DefaultTrackSelector.Parameters` | Extends `DefaultTrackSelector.Parameters` by adding fields that are specific to `DefaultTrackSelector`.
    `static class` | `DefaultTrackSelector.ParametersBuilder` | Deprecated. Use `DefaultTrackSelector.Parameters.Builder` instead.
    `protected static interface` | `DefaultTrackSelector.SelectionEligibility` | The extent to which tracks are eligible for selection.
    `static class` | `DefaultTrackSelector.SelectionOverride` | A track selection override.

    - ### Nested classes/interfaces inherited from class com.google.android.exoplayer2.trackselection.MappingTrackSelector

      `MappingTrackSelector.MappedTrackInfo`

    - ### Nested classes/interfaces inherited from class com.google.android.exoplayer2.trackselection.TrackSelector

      `TrackSelector.InvalidationListener`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `Context` | `context` |
    `protected static int` | `SELECTION_ELIGIBILITY_ADAPTIVE` | Track is eligible for both a fixed selection and as part of an adaptive selection with multiple tracks.
    `protected static int` | `SELECTION_ELIGIBILITY_FIXED` | Track is eligible for a fixed selection with one track.
    `protected static int` | `SELECTION_ELIGIBILITY_NO` | Track is not eligible for selection.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultTrackSelector()` | Deprecated. Use `DefaultTrackSelector(Context)` instead.
    `DefaultTrackSelector​(Context context)` |
    `DefaultTrackSelector​(Context context, ExoTrackSelection.Factory trackSelectionFactory)` |
    `DefaultTrackSelector​(Context context, TrackSelectionParameters parameters)` |
    `DefaultTrackSelector​(Context context, TrackSelectionParameters parameters, ExoTrackSelection.Factory trackSelectionFactory)` |
    `DefaultTrackSelector​(TrackSelectionParameters parameters, ExoTrackSelection.Factory trackSelectionFactory)` | Deprecated. Use `DefaultTrackSelector(Context, TrackSelectionParameters, ExoTrackSelection.Factory)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `DefaultTrackSelector.Parameters.Builder` | `buildUponParameters()` | Returns a new `DefaultTrackSelector.Parameters.Builder` initialized with the current selection parameters.
    `protected static int` | `getFormatLanguageScore​(Format format, String language, boolean allowUndeterminedFormatLanguage)` | Returns a score for how well a language specified in a `Format` matches a given language.
    `DefaultTrackSelector.Parameters` | `getParameters()` | Returns the current parameters for track selection.
    `boolean` | `isSetParametersSupported()` | Returns if this `TrackSelector` supports `TrackSelector.setParameters(TrackSelectionParameters)`.
    `protected static boolean` | `isSupported​(@com.google.android.exoplayer2.RendererCapabilities.Capabilities int formatSupport, boolean allowExceedsCapabilities)` | Returns true if the `C.FormatSupport` in the given `RendererCapabilities.Capabilities` is `C.FORMAT_HANDLED` or if `allowExceedsCapabilities` is set and the format support is `C.FORMAT_EXCEEDS_CAPABILITIES`.
    `protected static String` | `normalizeUndeterminedLanguageToNull​(String language)` | Normalizes the input string to null if it does not define a language, or returns it otherwise.
    `void` | `release()` | Called by the player to release the selector.
    `protected @NullableType ExoTrackSelection.Definition[]` | `selectAllTracks​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo, @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports, @com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports, DefaultTrackSelector.Parameters params)` | Called from `selectTracks(MappedTrackInfo, int[][][], int[], MediaPeriodId, Timeline)` to make a track selection for each renderer, prior to overrides and disabled flags being applied.
    `protected Pair<ExoTrackSelection.Definition,​Integer>` | `selectAudioTrack​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo, @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports, @com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports, DefaultTrackSelector.Parameters params)` | Called by `selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)` to create a `ExoTrackSelection.Definition` for an audio track selection.
    `protected ExoTrackSelection.Definition` | `selectOtherTrack​(int trackType, TrackGroupArray groups, @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][] formatSupport, DefaultTrackSelector.Parameters params)` | Called by `selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)` to create a `ExoTrackSelection` for a renderer whose type is neither video, audio or text.
    `protected Pair<ExoTrackSelection.Definition,​Integer>` | `selectTextTrack​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo, @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports, DefaultTrackSelector.Parameters params, String selectedAudioLanguage)` | Called by `selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)` to create a `ExoTrackSelection.Definition` for a text track selection.
    `protected Pair<@NullableType RendererConfiguration[],​@NullableType ExoTrackSelection[]>` | `selectTracks​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo, @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports, @com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupport, MediaSource.MediaPeriodId mediaPeriodId, Timeline timeline)` | Given mapped track information, returns a track selection and configuration for each renderer.
    `protected Pair<ExoTrackSelection.Definition,​Integer>` | `selectVideoTrack​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo, @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports, @com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int[] mixedMimeTypeSupports, DefaultTrackSelector.Parameters params)` | Called by `selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)` to create a `ExoTrackSelection.Definition` for a video track selection.
    `void` | `setAudioAttributes​(AudioAttributes audioAttributes)` | Called by the player to set the `AudioAttributes` that will be used for playback.
    `void` | `setParameters​(DefaultTrackSelector.Parameters.Builder parametersBuilder)` | Atomically sets the provided parameters for track selection.
    `void` | `setParameters​(DefaultTrackSelector.ParametersBuilder parametersBuilder)` | Deprecated. Use `setParameters(Parameters.Builder)` instead.
    `void` | `setParameters​(TrackSelectionParameters parameters)` | Called by the player to provide parameters for track selection.

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

      `getCurrentMappedTrackInfo, onSelectionActivated, selectTracks`

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

      `getBandwidthMeter, init, invalidate`

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

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

- - ### Field Detail

    - #### SELECTION_ELIGIBILITY_NO

          protected static final int SELECTION_ELIGIBILITY_NO

      Track is not eligible for selection.
      See Also:
        Constant Field Values

    - #### SELECTION_ELIGIBILITY_FIXED

          protected static final int SELECTION_ELIGIBILITY_FIXED

      Track is eligible for a fixed selection with one track.
      See Also:
        Constant Field Values

    - #### SELECTION_ELIGIBILITY_ADAPTIVE

          protected static final int SELECTION_ELIGIBILITY_ADAPTIVE

      Track is eligible for both a fixed selection and as part of an adaptive selection with multiple tracks.
      See Also:
        Constant Field Values

    - #### context

          @Nullable
          public final Context context

  - ### Constructor Detail

    - #### DefaultTrackSelector

          @Deprecated
          public DefaultTrackSelector()

      Deprecated.
      Use `DefaultTrackSelector(Context)` instead.

    - #### DefaultTrackSelector

          public DefaultTrackSelector​(Context context)

      Parameters:
        `context` - Any `Context`.

    - #### DefaultTrackSelector

          public DefaultTrackSelector​(Context context,
                                      ExoTrackSelection.Factory trackSelectionFactory)

      Parameters:
        `context` - Any `Context`.
        `trackSelectionFactory` - A factory for `ExoTrackSelection`s.

    - #### DefaultTrackSelector

          public DefaultTrackSelector​(Context context,
                                      TrackSelectionParameters parameters)

      Parameters:
        `context` - Any `Context`.
        `parameters` - Initial `TrackSelectionParameters`.

    - #### DefaultTrackSelector

          @Deprecated
          public DefaultTrackSelector​(TrackSelectionParameters parameters,
                                      ExoTrackSelection.Factory trackSelectionFactory)

      Deprecated.
      Use `DefaultTrackSelector(Context, TrackSelectionParameters, ExoTrackSelection.Factory)`

    - #### DefaultTrackSelector

          public DefaultTrackSelector​(Context context,
                                      TrackSelectionParameters parameters,
                                      ExoTrackSelection.Factory trackSelectionFactory)

      Parameters:
        `context` - Any `Context`.
        `parameters` - Initial `TrackSelectionParameters`.
        `trackSelectionFactory` - A factory for `ExoTrackSelection`s.

  - ### Method Detail

    - #### release

          public void release()

      Description copied from class: `TrackSelector`
      Called by the player to release the selector. The selector cannot be used until `TrackSelector.init(InvalidationListener, BandwidthMeter)` is called again.
      Overrides:
        `release` in class `TrackSelector`

    - #### getParameters

          public DefaultTrackSelector.Parameters getParameters()

      Description copied from class: `TrackSelector`
      Returns the current parameters for track selection.
      Overrides:
        `getParameters` in class `TrackSelector`

    - #### isSetParametersSupported

          public boolean isSetParametersSupported()

      Description copied from class: `TrackSelector`
      Returns if this `TrackSelector` supports `TrackSelector.setParameters(TrackSelectionParameters)`.

      The same value is always returned for a given `TrackSelector` instance.

      Overrides:
        `isSetParametersSupported` in class `TrackSelector`

    - #### setParameters

          public void setParameters​(TrackSelectionParameters parameters)

      Description copied from class: `TrackSelector`
      Called by the player to provide parameters for track selection.

      Only supported if `TrackSelector.isSetParametersSupported()` returns true.

      Overrides:
        `setParameters` in class `TrackSelector`
      Parameters:
        `parameters` - The parameters for track selection.

    - #### setAudioAttributes

          public void setAudioAttributes​(AudioAttributes audioAttributes)

      Description copied from class: `TrackSelector`
      Called by the player to set the `AudioAttributes` that will be used for playback.
      Overrides:
        `setAudioAttributes` in class `TrackSelector`

    - #### setParameters

          @Deprecated
          public void setParameters​(DefaultTrackSelector.ParametersBuilder parametersBuilder)

      Deprecated.
      Use `setParameters(Parameters.Builder)` instead.

    - #### setParameters

          public void setParameters​(DefaultTrackSelector.Parameters.Builder parametersBuilder)

      Atomically sets the provided parameters for track selection.
      Parameters:
        `parametersBuilder` - A builder from which to obtain the parameters for track selection.

    - #### buildUponParameters

          public DefaultTrackSelector.Parameters.Builder buildUponParameters()

      Returns a new `DefaultTrackSelector.Parameters.Builder` initialized with the current selection parameters.

    - #### selectTracks

          protected final Pair<@NullableType RendererConfiguration[],​@NullableType ExoTrackSelection[]> selectTracks​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
                                                                                                                           @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
                                                                                                                           @com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupport,
                                                                                                                           MediaSource.MediaPeriodId mediaPeriodId,
                                                                                                                           Timeline timeline)
                                                                                                                    throws ExoPlaybackException

      Description copied from class: `MappingTrackSelector`
      Given mapped track information, returns a track selection and configuration for each renderer.
      Specified by:
        `selectTracks` in class `MappingTrackSelector`
      Parameters:
        `mappedTrackInfo` - Mapped track information.
        `rendererFormatSupports` - The `RendererCapabilities.Capabilities` for each mapped track, indexed by renderer, track group and track (in that order).
        `rendererMixedMimeTypeAdaptationSupport` - The `RendererCapabilities.AdaptiveSupport` for mixed MIME type adaptation for the renderer.
        `mediaPeriodId` - The `MediaSource.MediaPeriodId` of the period for which tracks are to be selected.
        `timeline` - The `Timeline` holding the period for which tracks are to be selected.
      Returns:
        A pair consisting of the track selections and configurations for each renderer. A null configuration indicates the renderer should be disabled, in which case the track selection will also be null. A track selection may also be null for a non-disabled renderer if `RendererCapabilities.getTrackType()` is `C.TRACK_TYPE_NONE`.
      Throws:
        `ExoPlaybackException` - If an error occurs while selecting the tracks.

    - #### selectAllTracks

          protected @NullableType ExoTrackSelection.Definition[] selectAllTracks​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
                                                                                 @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
                                                                                 @com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports,
                                                                                 DefaultTrackSelector.Parameters params)
                                                                          throws ExoPlaybackException

      Called from `selectTracks(MappedTrackInfo, int[][][], int[], MediaPeriodId, Timeline)` to make a track selection for each renderer, prior to overrides and disabled flags being applied.

      The implementation should not account for overrides and disabled flags. Track selections generated by this method will be overridden to account for these properties.

      Parameters:
        `mappedTrackInfo` - Mapped track information.
        `rendererFormatSupports` - The `RendererCapabilities.Capabilities` for each mapped track, indexed by renderer, track group and track (in that order).
        `rendererMixedMimeTypeAdaptationSupports` - The `RendererCapabilities.AdaptiveSupport` for mixed MIME type adaptation for the renderer.
      Returns:
        The `ExoTrackSelection.Definition`s for the renderers. A null entry indicates no selection was made.
      Throws:
        `ExoPlaybackException` - If an error occurs while selecting the tracks.

    - #### selectVideoTrack

          @Nullable
          protected Pair<ExoTrackSelection.Definition,​Integer> selectVideoTrack​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
                                                                                      @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
                                                                                      @com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int[] mixedMimeTypeSupports,
                                                                                      DefaultTrackSelector.Parameters params)
                                                                               throws ExoPlaybackException

      Called by `selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)` to create a `ExoTrackSelection.Definition` for a video track selection.
      Parameters:
        `mappedTrackInfo` - Mapped track information.
        `rendererFormatSupports` - The `RendererCapabilities.Capabilities` for each mapped track, indexed by renderer, track group and track (in that order).
        `mixedMimeTypeSupports` - The `RendererCapabilities.AdaptiveSupport` for mixed MIME type adaptation for the renderer.
        `params` - The selector's current constraint parameters.
      Returns:
        A pair of the selected `ExoTrackSelection.Definition` and the corresponding renderer index, or null if no selection was made.
      Throws:
        `ExoPlaybackException` - If an error occurs while selecting the tracks.

    - #### selectAudioTrack

          @Nullable
          protected Pair<ExoTrackSelection.Definition,​Integer> selectAudioTrack​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
                                                                                      @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
                                                                                      @com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports,
                                                                                      DefaultTrackSelector.Parameters params)
                                                                               throws ExoPlaybackException

      Called by `selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)` to create a `ExoTrackSelection.Definition` for an audio track selection.
      Parameters:
        `mappedTrackInfo` - Mapped track information.
        `rendererFormatSupports` - The `RendererCapabilities.Capabilities` for each mapped track, indexed by renderer, track group and track (in that order).
        `rendererMixedMimeTypeAdaptationSupports` - The `RendererCapabilities.AdaptiveSupport` for mixed MIME type adaptation for the renderer.
        `params` - The selector's current constraint parameters.
      Returns:
        A pair of the selected `ExoTrackSelection.Definition` and the corresponding renderer index, or null if no selection was made.
      Throws:
        `ExoPlaybackException` - If an error occurs while selecting the tracks.

    - #### selectTextTrack

          @Nullable
          protected Pair<ExoTrackSelection.Definition,​Integer> selectTextTrack​(MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
                                                                                     @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
                                                                                     DefaultTrackSelector.Parameters params,
                                                                                     @Nullable
                                                                                     String selectedAudioLanguage)
                                                                              throws ExoPlaybackException

      Called by `selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)` to create a `ExoTrackSelection.Definition` for a text track selection.
      Parameters:
        `mappedTrackInfo` - Mapped track information.
        `rendererFormatSupports` - The `RendererCapabilities.Capabilities` for each mapped track, indexed by renderer, track group and track (in that order).
        `params` - The selector's current constraint parameters.
        `selectedAudioLanguage` - The language of the selected audio track. May be null if the selected audio track declares no language or no audio track was selected.
      Returns:
        A pair of the selected `ExoTrackSelection.Definition` and the corresponding renderer index, or null if no selection was made.
      Throws:
        `ExoPlaybackException` - If an error occurs while selecting the tracks.

    - #### selectOtherTrack

          @Nullable
          protected ExoTrackSelection.Definition selectOtherTrack​(int trackType,
                                                                  TrackGroupArray groups,
                                                                  @com.google.android.exoplayer2.RendererCapabilities.Capabilities int[][] formatSupport,
                                                                  DefaultTrackSelector.Parameters params)
                                                           throws ExoPlaybackException

      Called by `selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)` to create a `ExoTrackSelection` for a renderer whose type is neither video, audio or text.
      Parameters:
        `trackType` - The type of the renderer.
        `groups` - The `TrackGroupArray` mapped to the renderer.
        `formatSupport` - The `RendererCapabilities.Capabilities` for each mapped track, indexed by track group and track (in that order).
        `params` - The selector's current constraint parameters.
      Returns:
        The `ExoTrackSelection` for the renderer, or null if no selection was made.
      Throws:
        `ExoPlaybackException` - If an error occurs while selecting the tracks.

    - #### isSupported

          protected static boolean isSupported​(@com.google.android.exoplayer2.RendererCapabilities.Capabilities int formatSupport,
                                               boolean allowExceedsCapabilities)

      Returns true if the `C.FormatSupport` in the given `RendererCapabilities.Capabilities` is `C.FORMAT_HANDLED` or if `allowExceedsCapabilities` is set and the format support is `C.FORMAT_EXCEEDS_CAPABILITIES`.
      Parameters:
        `formatSupport` - `RendererCapabilities.Capabilities`.
        `allowExceedsCapabilities` - Whether to return true if `C.FormatSupport` is `C.FORMAT_EXCEEDS_CAPABILITIES`.
      Returns:
        True if `C.FormatSupport` is `C.FORMAT_HANDLED`, or if `allowExceedsCapabilities` is set and the format support is `C.FORMAT_EXCEEDS_CAPABILITIES`.

    - #### normalizeUndeterminedLanguageToNull

          @Nullable
          protected static String normalizeUndeterminedLanguageToNull​(@Nullable
                                                                      String language)

      Normalizes the input string to null if it does not define a language, or returns it otherwise.
      Parameters:
        `language` - The string.
      Returns:
        The string, optionally normalized to null if it does not define a language.

    - #### getFormatLanguageScore

          protected static int getFormatLanguageScore​(Format format,
                                                      @Nullable
                                                      String language,
                                                      boolean allowUndeterminedFormatLanguage)

      Returns a score for how well a language specified in a `Format` matches a given language.
      Parameters:
        `format` - The `Format`.
        `language` - The language, or null.
        `allowUndeterminedFormatLanguage` - Whether matches with an empty or undetermined format language tag are allowed.
      Returns:
        A score of 4 if the languages match fully, a score of 3 if the languages match partly, a score of 2 if the languages don't match but belong to the same main language, a score of 1 if the format language is undetermined and such a match is allowed, and a score of 0 if the languages don't match at all.