public class DefaultTrackSelector extends MappingTrackSelector
TrackSelector suitable for most use cases.
DefaultTrackSelector.Parameters that constrain the track
selection process. For example an instance can specify a preferred language for
the audio track, and impose constraints on the maximum video resolution that should be selected
for adaptive playbacks. Modifying the parameters is simple:
Parameters currentParameters = trackSelector.getParameters();
// Generate new parameters to prefer German audio and impose a maximum video size constraint.
Parameters newParameters = currentParameters
.withPreferredAudioLanguage("deu")
.withMaxVideoSize(1024, 768);
// Set the new parameters on the selector.
trackSelector.setParameters(newParameters);
There are several benefits to using constraint based track selection instead of specific track
overrides:
MappingTrackSelector, and so inherits its support for setting
specific track overrides, disabling renderers and configuring tunneled media playback. See
MappingTrackSelector for details.
MappingTrackSelector or TrackSelector from
scratch.| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultTrackSelector.Parameters
Constraint parameters for
DefaultTrackSelector. |
static class |
DefaultTrackSelector.ParametersBuilder
A builder for
DefaultTrackSelector.Parameters. |
MappingTrackSelector.MappedTrackInfo, MappingTrackSelector.SelectionOverrideTrackSelector.InvalidationListener| Constructor and Description |
|---|
DefaultTrackSelector()
Constructs an instance that does not support adaptive track selection.
|
DefaultTrackSelector(BandwidthMeter bandwidthMeter)
Constructs an instance that supports adaptive track selection.
|
DefaultTrackSelector(TrackSelection.Factory adaptiveTrackSelectionFactory)
Constructs an instance that uses a factory to create adaptive track selections.
|
| Modifier and Type | Method and Description |
|---|---|
protected static boolean |
formatHasLanguage(Format format,
java.lang.String language)
|
protected static boolean |
formatHasNoLanguage(Format format)
Returns whether a
Format does not define a language. |
DefaultTrackSelector.Parameters |
getParameters()
Gets the current selection parameters.
|
protected static boolean |
isSupported(int formatSupport,
boolean allowExceedsCapabilities)
Applies the
RendererCapabilities.FORMAT_SUPPORT_MASK to a value obtained from
RendererCapabilities.supportsFormat(Format), returning true if the result is
RendererCapabilities.FORMAT_HANDLED or if allowExceedsCapabilities is set
and the result is RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES. |
protected TrackSelection |
selectAudioTrack(TrackGroupArray groups,
int[][] formatSupport,
DefaultTrackSelector.Parameters params,
TrackSelection.Factory adaptiveTrackSelectionFactory)
Called by
selectTracks(RendererCapabilities[], TrackGroupArray[], int[][][]) to
create a TrackSelection for an audio renderer. |
protected TrackSelection |
selectOtherTrack(int trackType,
TrackGroupArray groups,
int[][] formatSupport,
DefaultTrackSelector.Parameters params)
Called by
selectTracks(RendererCapabilities[], TrackGroupArray[], int[][][]) to
create a TrackSelection for a renderer whose type is neither video, audio or text. |
protected TrackSelection |
selectTextTrack(TrackGroupArray groups,
int[][] formatSupport,
DefaultTrackSelector.Parameters params)
Called by
selectTracks(RendererCapabilities[], TrackGroupArray[], int[][][]) to
create a TrackSelection for a text renderer. |
protected TrackSelection[] |
selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray[] rendererTrackGroupArrays,
int[][][] rendererFormatSupports)
Given an array of renderer capabilities and the
TrackGroupArrays mapped to each of
them, provides a TrackSelection per renderer. |
protected TrackSelection |
selectVideoTrack(RendererCapabilities rendererCapabilities,
TrackGroupArray groups,
int[][] formatSupport,
DefaultTrackSelector.Parameters params,
TrackSelection.Factory adaptiveTrackSelectionFactory)
Called by
selectTracks(RendererCapabilities[], TrackGroupArray[], int[][][]) to
create a TrackSelection for a video renderer. |
void |
setParameters(DefaultTrackSelector.Parameters params)
Atomically sets the provided parameters for track selection.
|
clearSelectionOverride, clearSelectionOverrides, clearSelectionOverrides, getCurrentMappedTrackInfo, getRendererDisabled, getSelectionOverride, hasSelectionOverride, onSelectionActivated, selectTracks, setRendererDisabled, setSelectionOverride, setTunnelingAudioSessionIdinit, invalidatepublic DefaultTrackSelector()
public DefaultTrackSelector(BandwidthMeter bandwidthMeter)
BandwidthMeter to determine which individual track should be used during
playback.bandwidthMeter - The BandwidthMeter.public DefaultTrackSelector(TrackSelection.Factory adaptiveTrackSelectionFactory)
adaptiveTrackSelectionFactory - A factory for adaptive TrackSelections, or null if
the selector should not support adaptive tracks.public void setParameters(DefaultTrackSelector.Parameters params)
params - The parameters for track selection.public DefaultTrackSelector.Parameters getParameters()
protected TrackSelection[] selectTracks(RendererCapabilities[] rendererCapabilities, TrackGroupArray[] rendererTrackGroupArrays, int[][][] rendererFormatSupports) throws ExoPlaybackException
MappingTrackSelectorTrackGroupArrays mapped to each of
them, provides a TrackSelection per renderer.selectTracks in class MappingTrackSelectorrendererCapabilities - The RendererCapabilities of the renderers for which
TrackSelections are to be generated.rendererTrackGroupArrays - The TrackGroupArrays mapped to each of the renderers.rendererFormatSupports - The result of RendererCapabilities.supportsFormat(com.google.android.exoplayer2.Format) for
each mapped track, indexed by renderer index, track group index and track index (in that
order).ExoPlaybackException - If an error occurs while selecting the tracks.protected TrackSelection selectVideoTrack(RendererCapabilities rendererCapabilities, TrackGroupArray groups, int[][] formatSupport, DefaultTrackSelector.Parameters params, TrackSelection.Factory adaptiveTrackSelectionFactory) throws ExoPlaybackException
selectTracks(RendererCapabilities[], TrackGroupArray[], int[][][]) to
create a TrackSelection for a video renderer.rendererCapabilities - The RendererCapabilities for the renderer.groups - The TrackGroupArray mapped to the renderer.formatSupport - The result of RendererCapabilities.supportsFormat(com.google.android.exoplayer2.Format) for each mapped
track, indexed by track group index and track index (in that order).params - The selector's current constraint parameters.adaptiveTrackSelectionFactory - A factory for generating adaptive track selections, or
null if a fixed track selection is required.TrackSelection for the renderer, or null if no selection was made.ExoPlaybackException - If an error occurs while selecting the tracks.protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport, DefaultTrackSelector.Parameters params, TrackSelection.Factory adaptiveTrackSelectionFactory) throws ExoPlaybackException
selectTracks(RendererCapabilities[], TrackGroupArray[], int[][][]) to
create a TrackSelection for an audio renderer.groups - The TrackGroupArray mapped to the renderer.formatSupport - The result of RendererCapabilities.supportsFormat(com.google.android.exoplayer2.Format) for each mapped
track, indexed by track group index and track index (in that order).params - The selector's current constraint parameters.adaptiveTrackSelectionFactory - A factory for generating adaptive track selections, or
null if a fixed track selection is required.TrackSelection for the renderer, or null if no selection was made.ExoPlaybackException - If an error occurs while selecting the tracks.protected TrackSelection selectTextTrack(TrackGroupArray groups, int[][] formatSupport, DefaultTrackSelector.Parameters params) throws ExoPlaybackException
selectTracks(RendererCapabilities[], TrackGroupArray[], int[][][]) to
create a TrackSelection for a text renderer.groups - The TrackGroupArray mapped to the renderer.formatSupport - The result of RendererCapabilities.supportsFormat(com.google.android.exoplayer2.Format) for each mapped
track, indexed by track group index and track index (in that order).params - The selector's current constraint parameters.TrackSelection for the renderer, or null if no selection was made.ExoPlaybackException - If an error occurs while selecting the tracks.protected TrackSelection selectOtherTrack(int trackType, TrackGroupArray groups, int[][] formatSupport, DefaultTrackSelector.Parameters params) throws ExoPlaybackException
selectTracks(RendererCapabilities[], TrackGroupArray[], int[][][]) to
create a TrackSelection for a renderer whose type is neither video, audio or text.trackType - The type of the renderer.groups - The TrackGroupArray mapped to the renderer.formatSupport - The result of RendererCapabilities.supportsFormat(com.google.android.exoplayer2.Format) for each mapped
track, indexed by track group index and track index (in that order).params - The selector's current constraint parameters.TrackSelection for the renderer, or null if no selection was made.ExoPlaybackException - If an error occurs while selecting the tracks.protected static boolean isSupported(int formatSupport,
boolean allowExceedsCapabilities)
RendererCapabilities.FORMAT_SUPPORT_MASK to a value obtained from
RendererCapabilities.supportsFormat(Format), returning true if the result is
RendererCapabilities.FORMAT_HANDLED or if allowExceedsCapabilities is set
and the result is RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES.formatSupport - A value obtained from RendererCapabilities.supportsFormat(Format).allowExceedsCapabilities - Whether to return true if the format support component of the
value is RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES.RendererCapabilities.FORMAT_HANDLED, or
if allowExceedsCapabilities is set and the format support component is
RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES.protected static boolean formatHasNoLanguage(Format format)
Format does not define a language.