public abstract class TrackSelector
extends java.lang.Object
ExoPlayer responsible for selecting tracks to be consumed by each of
the player's Renderers. The DefaultTrackSelector implementation should be
suitable for most use cases.
init(InvalidationListener, BandwidthMeter).
selectTracks(RendererCapabilities[], TrackGroupArray). This typically occurs at the start
of playback, when the player starts to buffer a new period of the media being played, and
when the track selector invalidates its previous selections.
onSelectionActivated(Object).
TrackSelector.InvalidationListener.onTrackSelectionsInvalidated() on the TrackSelector.InvalidationListener
that was passed to init(InvalidationListener, BandwidthMeter). A track selector
may wish to do this if its configuration has changed, for example if it now wishes to
prefer audio tracks in a particular language. This will trigger the player to make new
track selections. Note that the player will have to re-buffer in the case that the new
track selection for the currently playing period differs from the one that was invalidated.
TrackSelectorResult returned by selectTracks(RendererCapabilities[],
TrackGroupArray) contains not only TrackSelections for each renderer, but also RendererConfigurations defining configuration parameters that the renderers should apply when
consuming the corresponding media. Whilst it may seem counter-intuitive for a track selector to
also specify renderer configuration information, in practice the two are tightly bound together.
It may only be possible to play a certain combination tracks if the renderers are configured in a
particular way. Equally, it may only be possible to configure renderers in a particular way if
certain tracks are selected. Hence it makes sense to determined the track selection and
corresponding renderer configurations in a single step.
TrackSelector.InvalidationListener.onTrackSelectionsInvalidated()
from any thread.| Modifier and Type | Class and Description |
|---|---|
static interface |
TrackSelector.InvalidationListener
Notified when selections previously made by a
TrackSelector are no longer valid. |
| Constructor and Description |
|---|
TrackSelector() |
| Modifier and Type | Method and Description |
|---|---|
protected BandwidthMeter |
getBandwidthMeter()
Returns a bandwidth meter which can be used by track selections to select tracks.
|
void |
init(TrackSelector.InvalidationListener listener,
BandwidthMeter bandwidthMeter)
Called by the player to initialize the selector.
|
protected void |
invalidate()
Calls
TrackSelector.InvalidationListener.onTrackSelectionsInvalidated() to invalidate all previously
generated track selections. |
abstract void |
onSelectionActivated(java.lang.Object info)
Called by the player when a
TrackSelectorResult previously generated by
selectTracks(RendererCapabilities[], TrackGroupArray) is activated. |
abstract TrackSelectorResult |
selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups)
Called by the player to perform a track selection.
|
public final void init(TrackSelector.InvalidationListener listener, BandwidthMeter bandwidthMeter)
listener - An invalidation listener that the selector can call to indicate that selections
it has previously made are no longer valid.bandwidthMeter - A bandwidth meter which can be used by track selections to select tracks.public abstract TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities, TrackGroupArray trackGroups) throws ExoPlaybackException
rendererCapabilities - 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 abstract void onSelectionActivated(java.lang.Object info)
TrackSelectorResult previously generated by
selectTracks(RendererCapabilities[], TrackGroupArray) is activated.info - The value of TrackSelectorResult.info in the activated selection.protected final void invalidate()
TrackSelector.InvalidationListener.onTrackSelectionsInvalidated() to invalidate all previously
generated track selections.protected final BandwidthMeter getBandwidthMeter()
init(InvalidationListener, BandwidthMeter) has been called.