public abstract class MappingTrackSelector extends TrackSelector
TrackSelectors that first establish a mapping between TrackGroups
and Renderers, and then from that mapping create a TrackSelection for each
renderer.
MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
TrackGroupArray rendererTrackGroups = mappedTrackInfo == null ? null
: mappedTrackInfo.getTrackGroups(rendererIndex);
If rendererTrackGroups is null then there aren't any currently mapped tracks, and so
setting an override isn't possible. Note that a Player.EventListener registered on the
player can be used to determine when the current tracks (and therefore the mapping) changes. If
rendererTrackGroups is non-null then an override can be set. The next step is to query
the properties of the available tracks to determine the groupIndex of the track group you
want to select and the trackIndices within it. You can then create and set the override:
trackSelector.setSelectionOverride(rendererIndex, rendererTrackGroups,
new SelectionOverride(trackSelectionFactory, groupIndex, trackIndices));
where trackSelectionFactory is a TrackSelection.Factory for generating concrete
TrackSelection instances for the override. It's also possible to pass null as the
selection override if you don't want any tracks to be selected.
Note that an override applies only when the track groups available to the renderer match the
TrackGroupArray for which the override was specified. Overrides can be cleared using
the clearSelectionOverride methods.
setRendererDisabled(int, boolean). Disabling a renderer
differs from setting a null override because the renderer is disabled unconditionally,
whereas a null override is applied only when the track groups available to the renderer
match the TrackGroupArray for which it was specified.
setTunnelingAudioSessionId(int) for more details.| Modifier and Type | Class and Description |
|---|---|
static class |
MappingTrackSelector.MappedTrackInfo
Provides mapped track information for each renderer.
|
static class |
MappingTrackSelector.SelectionOverride
A track selection override.
|
TrackSelector.InvalidationListener| Constructor and Description |
|---|
MappingTrackSelector() |
| Modifier and Type | Method and Description |
|---|---|
void |
clearSelectionOverride(int rendererIndex,
TrackGroupArray groups)
Clears a track selection override for the specified renderer and
TrackGroupArray. |
void |
clearSelectionOverrides()
Clears all track selection overrides for all renderers.
|
void |
clearSelectionOverrides(int rendererIndex)
Clears all track selection overrides for the specified renderer.
|
MappingTrackSelector.MappedTrackInfo |
getCurrentMappedTrackInfo()
Returns the mapping information for the currently active track selection, or null if no
selection is currently active.
|
boolean |
getRendererDisabled(int rendererIndex)
Returns whether the renderer is disabled.
|
MappingTrackSelector.SelectionOverride |
getSelectionOverride(int rendererIndex,
TrackGroupArray groups)
Returns the override for the specified renderer and
TrackGroupArray. |
boolean |
hasSelectionOverride(int rendererIndex,
TrackGroupArray groups)
Returns whether there is an override for the specified renderer and
TrackGroupArray. |
void |
onSelectionActivated(java.lang.Object info)
Called by the player when a
TrackSelectorResult previously generated by
TrackSelector.selectTracks(RendererCapabilities[], TrackGroupArray) is activated. |
TrackSelectorResult |
selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups)
Called by the player to perform a track selection.
|
protected abstract 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. |
void |
setRendererDisabled(int rendererIndex,
boolean disabled)
Sets whether the renderer at the specified index is disabled.
|
void |
setSelectionOverride(int rendererIndex,
TrackGroupArray groups,
MappingTrackSelector.SelectionOverride override)
Overrides the track selection for the renderer at the specified index.
|
void |
setTunnelingAudioSessionId(int tunnelingAudioSessionId)
Enables or disables tunneling.
|
init, invalidatepublic final MappingTrackSelector.MappedTrackInfo getCurrentMappedTrackInfo()
public final void setRendererDisabled(int rendererIndex,
boolean disabled)
rendererIndex - The renderer index.disabled - Whether the renderer is disabled.public final boolean getRendererDisabled(int rendererIndex)
rendererIndex - The renderer index.public final void setSelectionOverride(int rendererIndex,
TrackGroupArray groups,
MappingTrackSelector.SelectionOverride override)
When the TrackGroupArray mapped to the renderer matches the one provided, the override
is applied. When the TrackGroupArray does not match, the override has no effect. The
override replaces any previous override for the specified TrackGroupArray for the
specified Renderer.
Passing a null override will cause the renderer to be disabled when the
TrackGroupArray mapped to it matches the one provided. When the TrackGroupArray
does not match a null override has no effect. Hence a null override differs
from disabling the renderer using setRendererDisabled(int, boolean) because the
renderer is disabled conditionally on the TrackGroupArray mapped to it, where-as
setRendererDisabled(int, boolean) disables the renderer unconditionally.
To remove overrides use clearSelectionOverride(int, TrackGroupArray),
clearSelectionOverrides(int) or clearSelectionOverrides().
rendererIndex - The renderer index.groups - The TrackGroupArray for which the override should be applied.override - The override.public final boolean hasSelectionOverride(int rendererIndex,
TrackGroupArray groups)
TrackGroupArray.rendererIndex - The renderer index.groups - The TrackGroupArray.public final MappingTrackSelector.SelectionOverride getSelectionOverride(int rendererIndex, TrackGroupArray groups)
TrackGroupArray.rendererIndex - The renderer index.groups - The TrackGroupArray.public final void clearSelectionOverride(int rendererIndex,
TrackGroupArray groups)
TrackGroupArray.rendererIndex - The renderer index.groups - The TrackGroupArray for which the override should be cleared.public final void clearSelectionOverrides(int rendererIndex)
rendererIndex - The renderer index.public final void clearSelectionOverrides()
public void setTunnelingAudioSessionId(int tunnelingAudioSessionId)
C.generateAudioSessionIdV21(Context). To disable tunneling pass
C.AUDIO_SESSION_ID_UNSET. Tunneling will only be activated if it's both enabled and
supported by the audio and video renderers for the selected tracks.tunnelingAudioSessionId - The audio session id to use when tunneling, or
C.AUDIO_SESSION_ID_UNSET to disable tunneling.public final TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities, TrackGroupArray trackGroups) throws ExoPlaybackException
TrackSelectorselectTracks in class TrackSelectorrendererCapabilities - The RendererCapabilities of the renderers for which tracks
are to be selected.trackGroups - The available track groups.TrackSelectorResult describing the track selections.ExoPlaybackException - If an error occurs selecting tracks.public final void onSelectionActivated(java.lang.Object info)
TrackSelectorTrackSelectorResult previously generated by
TrackSelector.selectTracks(RendererCapabilities[], TrackGroupArray) is activated.onSelectionActivated in class TrackSelectorinfo - The value of TrackSelectorResult.info in the activated selection.protected abstract TrackSelection[] selectTracks(RendererCapabilities[] rendererCapabilities, TrackGroupArray[] rendererTrackGroupArrays, int[][][] rendererFormatSupports) throws ExoPlaybackException
TrackGroupArrays mapped to each of
them, provides a TrackSelection per renderer.rendererCapabilities - 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.