public abstract class TrackSelector extends Object
ExoPlayerresponsible for selecting tracks to be consumed by each of the player's
DefaultTrackSelectorimplementation should be suitable for most use cases.
#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.
TrackSelector.InvalidationListenerthat 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.
#selectTracks(RendererCapabilities, TrackGroupArray, MediaPeriodId, Timeline)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 determine the track selection and corresponding renderer configurations in a single step.
TrackSelector.InvalidationListener.onTrackSelectionsInvalidated()from any thread.
|Modifier and Type||Class and Description|
Notified when selections previously made by a
|Constructor and Description|
|Modifier and Type||Method and Description|
Returns a bandwidth meter which can be used by track selections to select tracks.
Called by the player to initialize the selector.
Called by the player when a
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
RendererCapabilitiesof the renderers for which tracks are to be selected.
trackGroups- The available track groups.
MediaSource.MediaPeriodIdof the period for which tracks are to be selected.
Timelineholding the period for which tracks are to be selected.
TrackSelectorResultdescribing the track selections.
ExoPlaybackException- If an error occurs selecting tracks.
public abstract void onSelectionActivated(Object info)
TrackSelectorResultpreviously generated by
#selectTracks(RendererCapabilities, TrackGroupArray, MediaPeriodId, Timeline)is activated.
info- The value of
TrackSelectorResult.infoin the activated selection.
protected final void invalidate()
TrackSelector.InvalidationListener.onTrackSelectionsInvalidated()to invalidate all previously generated track selections.