DefaultTrackSelector


@UnstableApi
public class DefaultTrackSelector extends MappingTrackSelector implements RendererCapabilities.Listener

Known direct subclasses

A default TrackSelector suitable for most use cases.

Modifying parameters

Track selection parameters should be modified by obtaining a initialized with the current TrackSelectionParameters from the player. The desired modifications can be made on the builder, and the resulting 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 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());

Summary

Nested types

Extends Parameters by adding fields that are specific to DefaultTrackSelector.

A builder for Parameters.

This class is deprecated.

Use Parameters.Builder instead.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
protected annotation DefaultTrackSelector.SelectionEligibility

The extent to which tracks are eligible for selection.

A track selection override.

Constants

static final int

Track is eligible for both a fixed selection and as part of an adaptive selection with multiple tracks.

static final int

Track is eligible for a fixed selection with one track.

static final int

Track is not eligible for selection.

Public constructors

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

This method is deprecated.

Use DefaultTrackSelector

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

Public methods

DefaultTrackSelector.Parameters.Builder

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

DefaultTrackSelector.Parameters

Returns the current parameters for track selection.

@Nullable RendererCapabilities.Listener

Returns the RendererCapabilities.Listener that the concrete instance uses to listen to the renderer capabilities changes.

boolean

Returns if this TrackSelector supports setParameters.

void

Called when the renderer capabilities are changed.

void

Called by the player to release the selector.

void

Called by the player to set the AudioAttributes that will be used for playback.

void

Atomically sets the provided parameters for track selection.

void

This method is deprecated.

Use setParameters instead.

void

Called by the player to provide parameters for track selection.

Protected methods

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.

static boolean
isSupported(
    @RendererCapabilities.Capabilities int formatSupport,
    boolean allowExceedsCapabilities
)

This method is deprecated.

Use isFormatSupported instead.

static @Nullable String

Normalizes the input string to null if it does not define a language, or returns it otherwise.

ExoTrackSelection.Definition[]
selectAllTracks(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    @RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports,
    DefaultTrackSelector.Parameters params
)

Called from selectTracks to make a track selection for each renderer, prior to overrides and disabled flags being applied.

@Nullable Pair<ExoTrackSelection.DefinitionInteger>
selectAudioTrack(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    @RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports,
    DefaultTrackSelector.Parameters params
)

Called by selectAllTracks to create a ExoTrackSelection.Definition for an audio track selection.

@Nullable Pair<ExoTrackSelection.DefinitionInteger>
selectImageTrack(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    DefaultTrackSelector.Parameters params
)

Called by selectAllTracks to create a ExoTrackSelection.Definition for an image track selection.

@Nullable ExoTrackSelection.Definition
selectOtherTrack(
    int trackType,
    TrackGroupArray groups,
    @RendererCapabilities.Capabilities int[][] formatSupport,
    DefaultTrackSelector.Parameters params
)

Called by selectAllTracks to create a ExoTrackSelection for a renderer whose type is neither video, audio or text.

@Nullable Pair<ExoTrackSelection.DefinitionInteger>
selectTextTrack(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    DefaultTrackSelector.Parameters params,
    @Nullable String selectedAudioLanguage
)

Called by selectAllTracks to create a ExoTrackSelection.Definition for a text track selection.

final Pair<RendererConfiguration[], ExoTrackSelection[]>
selectTracks(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    @RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupport,
    MediaSource.MediaPeriodId mediaPeriodId,
    Timeline timeline
)

Given mapped track information, returns a track selection and configuration for each renderer.

@Nullable Pair<ExoTrackSelection.DefinitionInteger>
selectVideoTrack(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    @RendererCapabilities.AdaptiveSupport int[] mixedMimeTypeSupports,
    DefaultTrackSelector.Parameters params
)

Called by selectAllTracks to create a ExoTrackSelection.Definition for a video track selection.

Inherited methods

From androidx.media3.exoplayer.trackselection.MappingTrackSelector
final @Nullable MappingTrackSelector.MappedTrackInfo

Returns the mapping information for the currently active track selection, or null if no selection is currently active.

final void

Called by the player when a TrackSelectorResult previously generated by selectTracks is activated.

final TrackSelectorResult
selectTracks(
    RendererCapabilities[] rendererCapabilities,
    TrackGroupArray trackGroups,
    MediaSource.MediaPeriodId periodId,
    Timeline timeline
)

Called by the player to perform a track selection.

From androidx.media3.exoplayer.trackselection.TrackSelector
final BandwidthMeter

Returns a bandwidth meter which can be used by track selections to select tracks.

TrackSelectionParameters

Returns the current parameters for track selection.

void
@CallSuper
init(
    TrackSelector.InvalidationListener listener,
    BandwidthMeter bandwidthMeter
)

Called by the player to initialize the selector.

final void

Calls onTrackSelectionsInvalidated to invalidate all previously generated track selections.

final void

Calls onRendererCapabilitiesChanged to invalidate all previously generated track selections because a renderer's capabilities have changed.

Constants

SELECTION_ELIGIBILITY_ADAPTIVE

protected static final int SELECTION_ELIGIBILITY_ADAPTIVE = 2

Track is eligible for both a fixed selection and as part of an adaptive selection with multiple tracks.

SELECTION_ELIGIBILITY_FIXED

protected static final int SELECTION_ELIGIBILITY_FIXED = 1

Track is eligible for a fixed selection with one track.

SELECTION_ELIGIBILITY_NO

protected static final int SELECTION_ELIGIBILITY_NO = 0

Track is not eligible for selection.

Public fields

context

public final @Nullable Context context

parameters

@GuardedBy(value = "lock")
public DefaultTrackSelector.Parameters parameters

Public constructors

DefaultTrackSelector

public DefaultTrackSelector(Context context)
Parameters
Context context

Any Context.

DefaultTrackSelector

public DefaultTrackSelector(
    Context context,
    TrackSelectionParameters parameters
)
Parameters
Context context

Any Context.

TrackSelectionParameters parameters

Initial TrackSelectionParameters.

DefaultTrackSelector

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

Any Context.

ExoTrackSelection.Factory trackSelectionFactory

A factory for ExoTrackSelections.

DefaultTrackSelector

public DefaultTrackSelector(
    TrackSelectionParameters parameters,
    ExoTrackSelection.Factory trackSelectionFactory
)

DefaultTrackSelector

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

Any Context.

TrackSelectionParameters parameters

Initial TrackSelectionParameters.

ExoTrackSelection.Factory trackSelectionFactory

A factory for ExoTrackSelections.

Public methods

buildUponParameters

public DefaultTrackSelector.Parameters.Builder buildUponParameters()

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

getParameters

public DefaultTrackSelector.Parameters getParameters()

Returns the current parameters for track selection.

getRendererCapabilitiesListener

public @Nullable RendererCapabilities.Listener getRendererCapabilitiesListener()

Returns the RendererCapabilities.Listener that the concrete instance uses to listen to the renderer capabilities changes. May be null if the implementation does not listen to the renderer capabilities changes.

isSetParametersSupported

public boolean isSetParametersSupported()

Returns if this TrackSelector supports setParameters.

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

onRendererCapabilitiesChanged

public void onRendererCapabilitiesChanged(Renderer renderer)

Called when the renderer capabilities are changed.

This method will be called on the playback thread.

Parameters
Renderer renderer

The renderer that has its capabilities changed.

release

public void release()

Called by the player to release the selector. The selector cannot be used until init is called again.

setAudioAttributes

public void setAudioAttributes(AudioAttributes audioAttributes)

Called by the player to set the AudioAttributes that will be used for playback.

setParameters

public void setParameters(
    DefaultTrackSelector.Parameters.Builder parametersBuilder
)

Atomically sets the provided parameters for track selection.

Parameters
DefaultTrackSelector.Parameters.Builder parametersBuilder

A builder from which to obtain the parameters for track selection.

setParameters

public void setParameters(
    DefaultTrackSelector.ParametersBuilder parametersBuilder
)

setParameters

public void setParameters(TrackSelectionParameters parameters)

Called by the player to provide parameters for track selection.

Only supported if isSetParametersSupported returns true.

Parameters
TrackSelectionParameters parameters

The parameters for track selection.

Protected methods

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 format

The Format.

@Nullable String language

The language, or null.

boolean allowUndeterminedFormatLanguage

Whether matches with an empty or undetermined format language tag are allowed.

Returns
int

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.

isSupported

protected static boolean isSupported(
    @RendererCapabilities.Capabilities int formatSupport,
    boolean allowExceedsCapabilities
)

normalizeUndeterminedLanguageToNull

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

Normalizes the input string to null if it does not define a language, or returns it otherwise.

Parameters
@Nullable String language

The string.

Returns
@Nullable String

The string, optionally normalized to null if it does not define a language.

selectAllTracks

protected ExoTrackSelection.Definition[] selectAllTracks(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    @RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports,
    DefaultTrackSelector.Parameters params
)

Called from selectTracks 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.

If selection parameters include audioOffloadPreferences with audioOffloadMode set to AUDIO_OFFLOAD_MODE_REQUIRED then only audio tracks will be selected. If no audio track is supported in offload, then no track will be selected.

Parameters
MappingTrackSelector.MappedTrackInfo mappedTrackInfo

Mapped track information.

@RendererCapabilities.Capabilities int[][][] rendererFormatSupports

The Capabilities for each mapped track, indexed by renderer, track group and track (in that order).

@RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports

The AdaptiveSupport for mixed MIME type adaptation for the renderer.

DefaultTrackSelector.Parameters params

The parameters to use for the track selection.

Returns
ExoTrackSelection.Definition[]

The ExoTrackSelection.Definitions for the renderers. A null entry indicates no selection was made.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs while selecting the tracks.

selectAudioTrack

protected @Nullable Pair<ExoTrackSelection.DefinitionIntegerselectAudioTrack(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    @RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports,
    DefaultTrackSelector.Parameters params
)

Called by selectAllTracks to create a ExoTrackSelection.Definition for an audio track selection.

Parameters
MappingTrackSelector.MappedTrackInfo mappedTrackInfo

Mapped track information.

@RendererCapabilities.Capabilities int[][][] rendererFormatSupports

The Capabilities for each mapped track, indexed by renderer, track group and track (in that order).

@RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports

The AdaptiveSupport for mixed MIME type adaptation for the renderer.

DefaultTrackSelector.Parameters params

The selector's current constraint parameters.

Returns
@Nullable Pair<ExoTrackSelection.DefinitionInteger>

A pair of the selected ExoTrackSelection.Definition and the corresponding renderer index, or null if no selection was made.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs while selecting the tracks.

selectImageTrack

protected @Nullable Pair<ExoTrackSelection.DefinitionIntegerselectImageTrack(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    DefaultTrackSelector.Parameters params
)

Called by selectAllTracks to create a ExoTrackSelection.Definition for an image track selection.

Parameters
MappingTrackSelector.MappedTrackInfo mappedTrackInfo

Mapped track information.

@RendererCapabilities.Capabilities int[][][] rendererFormatSupports

The Capabilities for each mapped track, indexed by renderer, track group and track (in that order).

DefaultTrackSelector.Parameters params

The selector's current constraint parameters.

Returns
@Nullable Pair<ExoTrackSelection.DefinitionInteger>

A pair of the selected ExoTrackSelection.Definition and the corresponding renderer index, or null if no selection was made.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs while selecting the tracks.

selectOtherTrack

protected @Nullable ExoTrackSelection.Definition selectOtherTrack(
    int trackType,
    TrackGroupArray groups,
    @RendererCapabilities.Capabilities int[][] formatSupport,
    DefaultTrackSelector.Parameters params
)

Called by selectAllTracks to create a ExoTrackSelection for a renderer whose type is neither video, audio or text.

Parameters
int trackType

The type of the renderer.

TrackGroupArray groups

The TrackGroupArray mapped to the renderer.

@RendererCapabilities.Capabilities int[][] formatSupport

The Capabilities for each mapped track, indexed by track group and track (in that order).

DefaultTrackSelector.Parameters params

The selector's current constraint parameters.

Returns
@Nullable ExoTrackSelection.Definition

The ExoTrackSelection for the renderer, or null if no selection was made.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs while selecting the tracks.

selectTextTrack

protected @Nullable Pair<ExoTrackSelection.DefinitionIntegerselectTextTrack(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    DefaultTrackSelector.Parameters params,
    @Nullable String selectedAudioLanguage
)

Called by selectAllTracks to create a ExoTrackSelection.Definition for a text track selection.

Parameters
MappingTrackSelector.MappedTrackInfo mappedTrackInfo

Mapped track information.

@RendererCapabilities.Capabilities int[][][] rendererFormatSupports

The Capabilities for each mapped track, indexed by renderer, track group and track (in that order).

DefaultTrackSelector.Parameters params

The selector's current constraint parameters.

@Nullable String 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
@Nullable Pair<ExoTrackSelection.DefinitionInteger>

A pair of the selected ExoTrackSelection.Definition and the corresponding renderer index, or null if no selection was made.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs while selecting the tracks.

selectTracks

protected final Pair<RendererConfiguration[], ExoTrackSelection[]> selectTracks(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    @RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupport,
    MediaSource.MediaPeriodId mediaPeriodId,
    Timeline timeline
)

Given mapped track information, returns a track selection and configuration for each renderer.

Parameters
MappingTrackSelector.MappedTrackInfo mappedTrackInfo

Mapped track information.

@RendererCapabilities.Capabilities int[][][] rendererFormatSupports

The Capabilities for each mapped track, indexed by renderer, track group and track (in that order).

@RendererCapabilities.AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupport

The AdaptiveSupport for mixed MIME type adaptation for the renderer.

MediaSource.MediaPeriodId mediaPeriodId

The MediaPeriodId of the period for which tracks are to be selected.

Timeline timeline

The Timeline holding the period for which tracks are to be selected.

Returns
Pair<RendererConfiguration[], ExoTrackSelection[]>

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 must also be null. A track selection may also be null for a non-disabled renderer if getTrackType is TRACK_TYPE_NONE.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs while selecting the tracks.

selectVideoTrack

protected @Nullable Pair<ExoTrackSelection.DefinitionIntegerselectVideoTrack(
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo,
    @RendererCapabilities.Capabilities int[][][] rendererFormatSupports,
    @RendererCapabilities.AdaptiveSupport int[] mixedMimeTypeSupports,
    DefaultTrackSelector.Parameters params
)

Called by selectAllTracks to create a ExoTrackSelection.Definition for a video track selection.

Parameters
MappingTrackSelector.MappedTrackInfo mappedTrackInfo

Mapped track information.

@RendererCapabilities.Capabilities int[][][] rendererFormatSupports

The Capabilities for each mapped track, indexed by renderer, track group and track (in that order).

@RendererCapabilities.AdaptiveSupport int[] mixedMimeTypeSupports

The AdaptiveSupport for mixed MIME type adaptation for the renderer.

DefaultTrackSelector.Parameters params

The selector's current constraint parameters.

Returns
@Nullable Pair<ExoTrackSelection.DefinitionInteger>

A pair of the selected ExoTrackSelection.Definition and the corresponding renderer index, or null if no selection was made.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs while selecting the tracks.