use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.
the class DefaultTrackSelector method selectOtherTrack.
// Generic track selection methods.
/**
* Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
* {@link ExoTrackSelection} for a renderer whose type is neither video, audio or text.
*
* @param trackType The type of the renderer.
* @param groups The {@link TrackGroupArray} mapped to the renderer.
* @param formatSupport The {@link Capabilities} for each mapped track, indexed by track group and
* track (in that order).
* @param params The selector's current constraint parameters.
* @return The {@link ExoTrackSelection} for the renderer, or null if no selection was made.
* @throws ExoPlaybackException If an error occurs while selecting the tracks.
*/
@Nullable
protected ExoTrackSelection.Definition selectOtherTrack(int trackType, TrackGroupArray groups, @Capabilities int[][] formatSupport, Parameters params) throws ExoPlaybackException {
@Nullable TrackGroup selectedGroup = null;
int selectedTrackIndex = 0;
@Nullable OtherTrackScore selectedTrackScore = null;
for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
TrackGroup trackGroup = groups.get(groupIndex);
@Capabilities int[] trackFormatSupport = formatSupport[groupIndex];
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
if (isSupported(trackFormatSupport[trackIndex], params.exceedRendererCapabilitiesIfNecessary)) {
Format format = trackGroup.getFormat(trackIndex);
OtherTrackScore trackScore = new OtherTrackScore(format, trackFormatSupport[trackIndex]);
if (selectedTrackScore == null || trackScore.compareTo(selectedTrackScore) > 0) {
selectedGroup = trackGroup;
selectedTrackIndex = trackIndex;
selectedTrackScore = trackScore;
}
}
}
}
return selectedGroup == null ? null : new ExoTrackSelection.Definition(selectedGroup, selectedTrackIndex);
}
use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.
the class DefaultTrackSelector method getApplicableOverrides.
/**
* Returns applicable overrides. Mapping from track type to a pair of override and renderer index
* for this override.
*/
private SparseArray<Pair<TrackSelectionOverride, Integer>> getApplicableOverrides(MappedTrackInfo mappedTrackInfo, Parameters params) {
SparseArray<Pair<TrackSelectionOverride, Integer>> applicableOverrides = new SparseArray<>();
// Iterate through all existing track groups to ensure only overrides for those groups are used.
int rendererCount = mappedTrackInfo.getRendererCount();
for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
for (int j = 0; j < rendererTrackGroups.length; j++) {
maybeUpdateApplicableOverrides(applicableOverrides, params.trackSelectionOverrides.getOverride(rendererTrackGroups.get(j)), rendererIndex);
}
}
// Also iterate unmapped groups to see if they have overrides.
TrackGroupArray unmappedGroups = mappedTrackInfo.getUnmappedTrackGroups();
for (int i = 0; i < unmappedGroups.length; i++) {
maybeUpdateApplicableOverrides(applicableOverrides, params.trackSelectionOverrides.getOverride(unmappedGroups.get(i)), /* rendererIndex= */
C.INDEX_UNSET);
}
return applicableOverrides;
}
use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.
the class TrackSelectionView method init.
/**
* Initialize the view to select tracks for a specified renderer using {@link MappedTrackInfo} and
* a set of {@link DefaultTrackSelector.Parameters}.
*
* @param mappedTrackInfo The {@link MappedTrackInfo}.
* @param rendererIndex The index of the renderer.
* @param isDisabled Whether the renderer should be initially shown as disabled.
* @param overrides List of initial overrides to be shown for this renderer. There must be at most
* one override for each track group. If {@link #setAllowMultipleOverrides(boolean)} hasn't
* been set to {@code true}, only the first override is used.
* @param trackFormatComparator An optional comparator used to determine the display order of the
* tracks within each track group.
* @param listener An optional listener for track selection updates.
*/
public void init(MappedTrackInfo mappedTrackInfo, int rendererIndex, boolean isDisabled, List<SelectionOverride> overrides, @Nullable Comparator<Format> trackFormatComparator, @Nullable TrackSelectionListener listener) {
this.mappedTrackInfo = mappedTrackInfo;
this.rendererIndex = rendererIndex;
this.isDisabled = isDisabled;
this.trackInfoComparator = trackFormatComparator == null ? null : (o1, o2) -> trackFormatComparator.compare(o1.format, o2.format);
this.listener = listener;
int maxOverrides = allowMultipleOverrides ? overrides.size() : Math.min(overrides.size(), 1);
for (int i = 0; i < maxOverrides; i++) {
SelectionOverride override = overrides.get(i);
this.overrides.put(override.groupIndex, override);
}
updateViews();
}
use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.
the class TrackSelectionView method updateViews.
// Private methods.
private void updateViews() {
// Remove previous per-track views.
for (int i = getChildCount() - 1; i >= 3; i--) {
removeViewAt(i);
}
if (mappedTrackInfo == null) {
// The view is not initialized.
disableView.setEnabled(false);
defaultView.setEnabled(false);
return;
}
disableView.setEnabled(true);
defaultView.setEnabled(true);
trackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
// Add per-track views.
trackViews = new CheckedTextView[trackGroups.length][];
boolean enableMultipleChoiceForMultipleOverrides = shouldEnableMultiGroupSelection();
for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
TrackGroup group = trackGroups.get(groupIndex);
boolean enableMultipleChoiceForAdaptiveSelections = shouldEnableAdaptiveSelection(groupIndex);
trackViews[groupIndex] = new CheckedTextView[group.length];
TrackInfo[] trackInfos = new TrackInfo[group.length];
for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
trackInfos[trackIndex] = new TrackInfo(groupIndex, trackIndex, group.getFormat(trackIndex));
}
if (trackInfoComparator != null) {
Arrays.sort(trackInfos, trackInfoComparator);
}
for (int trackIndex = 0; trackIndex < trackInfos.length; trackIndex++) {
if (trackIndex == 0) {
addView(inflater.inflate(R.layout.exo_list_divider, this, false));
}
int trackViewLayoutId = enableMultipleChoiceForAdaptiveSelections || enableMultipleChoiceForMultipleOverrides ? android.R.layout.simple_list_item_multiple_choice : android.R.layout.simple_list_item_single_choice;
CheckedTextView trackView = (CheckedTextView) inflater.inflate(trackViewLayoutId, this, false);
trackView.setBackgroundResource(selectableItemBackgroundResourceId);
trackView.setText(trackNameProvider.getTrackName(trackInfos[trackIndex].format));
trackView.setTag(trackInfos[trackIndex]);
if (mappedTrackInfo.getTrackSupport(rendererIndex, groupIndex, trackIndex) == C.FORMAT_HANDLED) {
trackView.setFocusable(true);
trackView.setOnClickListener(componentListener);
} else {
trackView.setFocusable(false);
trackView.setEnabled(false);
}
trackViews[groupIndex][trackIndex] = trackView;
addView(trackView);
}
}
updateViewStates();
}
use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.
the class TrackSelectionView method onTrackViewClicked.
private void onTrackViewClicked(View view) {
isDisabled = false;
TrackInfo trackInfo = (TrackInfo) Assertions.checkNotNull(view.getTag());
int groupIndex = trackInfo.groupIndex;
int trackIndex = trackInfo.trackIndex;
SelectionOverride override = overrides.get(groupIndex);
Assertions.checkNotNull(mappedTrackInfo);
if (override == null) {
// Start new override.
if (!allowMultipleOverrides && overrides.size() > 0) {
// Removed other overrides if we don't allow multiple overrides.
overrides.clear();
}
overrides.put(groupIndex, new SelectionOverride(groupIndex, trackIndex));
} else {
// An existing override is being modified.
int overrideLength = override.length;
int[] overrideTracks = override.tracks;
boolean isCurrentlySelected = ((CheckedTextView) view).isChecked();
boolean isAdaptiveAllowed = shouldEnableAdaptiveSelection(groupIndex);
boolean isUsingCheckBox = isAdaptiveAllowed || shouldEnableMultiGroupSelection();
if (isCurrentlySelected && isUsingCheckBox) {
// Remove the track from the override.
if (overrideLength == 1) {
// The last track is being removed, so the override becomes empty.
overrides.remove(groupIndex);
} else {
int[] tracks = getTracksRemoving(overrideTracks, trackIndex);
overrides.put(groupIndex, new SelectionOverride(groupIndex, tracks));
}
} else if (!isCurrentlySelected) {
if (isAdaptiveAllowed) {
// Add new track to adaptive override.
int[] tracks = getTracksAdding(overrideTracks, trackIndex);
overrides.put(groupIndex, new SelectionOverride(groupIndex, tracks));
} else {
// Replace existing track in override.
overrides.put(groupIndex, new SelectionOverride(groupIndex, trackIndex));
}
}
}
}
Aggregations