DefaultTrackSelector


@UnstableApi
class DefaultTrackSelector : MappingTrackSelector, 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

const Int

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

const Int

Track is eligible for a fixed selection with one track.

const Int

Track is not eligible for selection.

Public constructors

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

This function is deprecated.

Use DefaultTrackSelector

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

Public functions

DefaultTrackSelector.Parameters.Builder!

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

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.

Unit

Called when the renderer capabilities are changed.

Unit

Called by the player to release the selector.

Unit

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

Unit

Atomically sets the provided parameters for track selection.

Unit

This function is deprecated.

Use setParameters instead.

Unit

Called by the player to provide parameters for track selection.

Protected functions

java-static Int
getFormatLanguageScore(
    format: Format!,
    language: String?,
    allowUndeterminedFormatLanguage: Boolean
)

Returns a score for how well a language specified in a Format matches a given language.

java-static Boolean
isSupported(
    @RendererCapabilities.Capabilities formatSupport: Int,
    allowExceedsCapabilities: Boolean
)

This function is deprecated.

Use isFormatSupported instead.

java-static String?

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

Array<@NullableType ExoTrackSelection.Definition!>!
selectAllTracks(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    @RendererCapabilities.AdaptiveSupport rendererMixedMimeTypeAdaptationSupports: IntArray!,
    params: DefaultTrackSelector.Parameters!
)

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

Pair<ExoTrackSelection.Definition!, Int!>?
selectAudioTrack(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    @RendererCapabilities.AdaptiveSupport rendererMixedMimeTypeAdaptationSupports: IntArray!,
    params: DefaultTrackSelector.Parameters!
)

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

Pair<ExoTrackSelection.Definition!, Int!>?
selectImageTrack(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    params: DefaultTrackSelector.Parameters!
)

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

ExoTrackSelection.Definition?
selectOtherTrack(
    trackType: Int,
    groups: TrackGroupArray!,
    @RendererCapabilities.Capabilities formatSupport: Array<IntArray!>!,
    params: DefaultTrackSelector.Parameters!
)

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

Pair<ExoTrackSelection.Definition!, Int!>?
selectTextTrack(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    params: DefaultTrackSelector.Parameters!,
    selectedAudioLanguage: String?
)

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

Pair<Array<@NullableType RendererConfiguration!>!, Array<@NullableType ExoTrackSelection!>!>!
selectTracks(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    @RendererCapabilities.AdaptiveSupport rendererMixedMimeTypeAdaptationSupport: IntArray!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    timeline: Timeline!
)

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

Pair<ExoTrackSelection.Definition!, Int!>?
selectVideoTrack(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    @RendererCapabilities.AdaptiveSupport mixedMimeTypeSupports: IntArray!,
    params: DefaultTrackSelector.Parameters!
)

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

Public properties

Context?
DefaultTrackSelector.Parameters!
@GuardedBy(value = "lock")
parameters

Inherited functions

From androidx.media3.exoplayer.trackselection.MappingTrackSelector
Unit

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

TrackSelectorResult!
selectTracks(
    rendererCapabilities: Array<RendererCapabilities!>!,
    trackGroups: TrackGroupArray!,
    periodId: MediaSource.MediaPeriodId!,
    timeline: Timeline!
)

Called by the player to perform a track selection.

From androidx.media3.exoplayer.trackselection.TrackSelector
TrackSelectionParameters!

Returns the current parameters for track selection.

Unit
@CallSuper
init(
    listener: TrackSelector.InvalidationListener!,
    bandwidthMeter: BandwidthMeter!
)

Called by the player to initialize the selector.

Unit

Calls onTrackSelectionsInvalidated to invalidate all previously generated track selections.

Unit

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

Constants

SELECTION_ELIGIBILITY_ADAPTIVE

protected const val SELECTION_ELIGIBILITY_ADAPTIVE = 2: Int

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

SELECTION_ELIGIBILITY_FIXED

protected const val SELECTION_ELIGIBILITY_FIXED = 1: Int

Track is eligible for a fixed selection with one track.

SELECTION_ELIGIBILITY_NO

protected const val SELECTION_ELIGIBILITY_NO = 0: Int

Track is not eligible for selection.

Public constructors

DefaultTrackSelector

DefaultTrackSelector(context: Context!)
Parameters
context: Context!

Any Context.

DefaultTrackSelector

DefaultTrackSelector(
    context: Context!,
    parameters: TrackSelectionParameters!
)
Parameters
context: Context!

Any Context.

parameters: TrackSelectionParameters!

Initial TrackSelectionParameters.

DefaultTrackSelector

DefaultTrackSelector(
    context: Context!,
    trackSelectionFactory: ExoTrackSelection.Factory!
)
Parameters
context: Context!

Any Context.

trackSelectionFactory: ExoTrackSelection.Factory!

A factory for ExoTrackSelections.

DefaultTrackSelector

DefaultTrackSelector(
    parameters: TrackSelectionParameters!,
    trackSelectionFactory: ExoTrackSelection.Factory!
)

DefaultTrackSelector

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

Any Context.

parameters: TrackSelectionParameters!

Initial TrackSelectionParameters.

trackSelectionFactory: ExoTrackSelection.Factory!

A factory for ExoTrackSelections.

Public functions

buildUponParameters

fun buildUponParameters(): DefaultTrackSelector.Parameters.Builder!

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

getRendererCapabilitiesListener

fun getRendererCapabilitiesListener(): RendererCapabilities.Listener?

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

fun isSetParametersSupported(): Boolean

Returns if this TrackSelector supports setParameters.

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

onRendererCapabilitiesChanged

fun onRendererCapabilitiesChanged(renderer: Renderer!): Unit

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

fun release(): Unit

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

setAudioAttributes

fun setAudioAttributes(audioAttributes: AudioAttributes!): Unit

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

setParameters

fun setParameters(
    parametersBuilder: DefaultTrackSelector.Parameters.Builder!
): Unit

Atomically sets the provided parameters for track selection.

Parameters
parametersBuilder: DefaultTrackSelector.Parameters.Builder!

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

setParameters

fun setParameters(
    parametersBuilder: DefaultTrackSelector.ParametersBuilder!
): Unit

setParameters

fun setParameters(parameters: TrackSelectionParameters!): Unit

Called by the player to provide parameters for track selection.

Only supported if isSetParametersSupported returns true.

Parameters
parameters: TrackSelectionParameters!

The parameters for track selection.

Protected functions

getFormatLanguageScore

protected java-static fun getFormatLanguageScore(
    format: Format!,
    language: String?,
    allowUndeterminedFormatLanguage: Boolean
): Int

Returns a score for how well a language specified in a Format matches a given language.

Parameters
format: Format!

The Format.

language: String?

The language, or null.

allowUndeterminedFormatLanguage: Boolean

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 java-static fun isSupported(
    @RendererCapabilities.Capabilities formatSupport: Int,
    allowExceedsCapabilities: Boolean
): Boolean

normalizeUndeterminedLanguageToNull

protected java-static fun normalizeUndeterminedLanguageToNull(language: String?): String?

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

Parameters
language: String?

The string.

Returns
String?

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

selectAllTracks

protected fun selectAllTracks(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    @RendererCapabilities.AdaptiveSupport rendererMixedMimeTypeAdaptationSupports: IntArray!,
    params: DefaultTrackSelector.Parameters!
): Array<@NullableType ExoTrackSelection.Definition!>!

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
mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!

Mapped track information.

@RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!

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

@RendererCapabilities.AdaptiveSupport rendererMixedMimeTypeAdaptationSupports: IntArray!

The AdaptiveSupport for mixed MIME type adaptation for the renderer.

params: DefaultTrackSelector.Parameters!

The parameters to use for the track selection.

Returns
Array<@NullableType 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 fun selectAudioTrack(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    @RendererCapabilities.AdaptiveSupport rendererMixedMimeTypeAdaptationSupports: IntArray!,
    params: DefaultTrackSelector.Parameters!
): Pair<ExoTrackSelection.Definition!, Int!>?

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

Parameters
mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!

Mapped track information.

@RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!

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

@RendererCapabilities.AdaptiveSupport rendererMixedMimeTypeAdaptationSupports: IntArray!

The AdaptiveSupport for mixed MIME type adaptation for the renderer.

params: DefaultTrackSelector.Parameters!

The selector's current constraint parameters.

Returns
Pair<ExoTrackSelection.Definition!, Int!>?

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 fun selectImageTrack(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    params: DefaultTrackSelector.Parameters!
): Pair<ExoTrackSelection.Definition!, Int!>?

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

Parameters
mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!

Mapped track information.

@RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!

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

params: DefaultTrackSelector.Parameters!

The selector's current constraint parameters.

Returns
Pair<ExoTrackSelection.Definition!, Int!>?

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 fun selectOtherTrack(
    trackType: Int,
    groups: TrackGroupArray!,
    @RendererCapabilities.Capabilities formatSupport: Array<IntArray!>!,
    params: DefaultTrackSelector.Parameters!
): ExoTrackSelection.Definition?

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

Parameters
trackType: Int

The type of the renderer.

groups: TrackGroupArray!

The TrackGroupArray mapped to the renderer.

@RendererCapabilities.Capabilities formatSupport: Array<IntArray!>!

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

params: DefaultTrackSelector.Parameters!

The selector's current constraint parameters.

Returns
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 fun selectTextTrack(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    params: DefaultTrackSelector.Parameters!,
    selectedAudioLanguage: String?
): Pair<ExoTrackSelection.Definition!, Int!>?

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

Parameters
mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!

Mapped track information.

@RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!

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

params: DefaultTrackSelector.Parameters!

The selector's current constraint parameters.

selectedAudioLanguage: String?

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
Pair<ExoTrackSelection.Definition!, Int!>?

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 fun selectTracks(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    @RendererCapabilities.AdaptiveSupport rendererMixedMimeTypeAdaptationSupport: IntArray!,
    mediaPeriodId: MediaSource.MediaPeriodId!,
    timeline: Timeline!
): Pair<Array<@NullableType RendererConfiguration!>!, Array<@NullableType ExoTrackSelection!>!>!

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

Parameters
mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!

Mapped track information.

@RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!

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

@RendererCapabilities.AdaptiveSupport rendererMixedMimeTypeAdaptationSupport: IntArray!

The AdaptiveSupport for mixed MIME type adaptation for the renderer.

mediaPeriodId: MediaSource.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<Array<@NullableType RendererConfiguration!>!, Array<@NullableType 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 fun selectVideoTrack(
    mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!,
    @RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!,
    @RendererCapabilities.AdaptiveSupport mixedMimeTypeSupports: IntArray!,
    params: DefaultTrackSelector.Parameters!
): Pair<ExoTrackSelection.Definition!, Int!>?

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

Parameters
mappedTrackInfo: MappingTrackSelector.MappedTrackInfo!

Mapped track information.

@RendererCapabilities.Capabilities rendererFormatSupports: Array<Array<IntArray!>!>!

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

@RendererCapabilities.AdaptiveSupport mixedMimeTypeSupports: IntArray!

The AdaptiveSupport for mixed MIME type adaptation for the renderer.

params: DefaultTrackSelector.Parameters!

The selector's current constraint parameters.

Returns
Pair<ExoTrackSelection.Definition!, Int!>?

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.

Public properties

context

val contextContext?

parameters

@GuardedBy(value = "lock")
val parametersDefaultTrackSelector.Parameters!