MappingTrackSelector
public abstract class TrackSelector extends Object
ExoPlayer
responsible for selecting tracks to be consumed by each of
the player's Renderer
s. The DefaultTrackSelector
implementation should be
suitable for most use cases.
init(InvalidationListener, BandwidthMeter)
.
selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId, Timeline)
. 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.
Implementing subclasses can trigger invalidation by calling invalidate()
, which
will call TrackSelector.InvalidationListener.onTrackSelectionsInvalidated()
.
TrackSelectorResult
returned by selectTracks(RendererCapabilities[],
TrackGroupArray, MediaPeriodId, Timeline)
contains not only TrackSelection
s for each
renderer, but also RendererConfiguration
s 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
determine the track selection and corresponding renderer configurations in a single step.
TrackSelector.InvalidationListener.onTrackSelectionsInvalidated()
from any thread.Modifier and Type | Class | Description |
---|---|---|
static interface |
TrackSelector.InvalidationListener |
Notified when selections previously made by a
TrackSelector are no longer valid. |
Constructor | Description |
---|---|
TrackSelector() |
Modifier and Type | Method | 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(Object info) |
Called by the player when a
TrackSelectorResult previously generated by selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId, Timeline) is activated. |
abstract TrackSelectorResult |
selectTracks(RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaSource.MediaPeriodId periodId,
Timeline timeline) |
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, MediaSource.MediaPeriodId periodId, Timeline timeline) throws ExoPlaybackException
rendererCapabilities
- The RendererCapabilities
of the renderers for which tracks
are to be selected.trackGroups
- The available track groups.periodId
- The MediaSource.MediaPeriodId
of the period for which tracks are to be selected.timeline
- The Timeline
holding the period for which tracks are to be selected.TrackSelectorResult
describing the track selections.ExoPlaybackException
- If an error occurs selecting tracks.public abstract void onSelectionActivated(@Nullable Object info)
TrackSelectorResult
previously generated by selectTracks(RendererCapabilities[], TrackGroupArray, MediaPeriodId, Timeline)
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.