Search in sources :

Example 6 with MappedTrackInfo

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);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Capabilities(androidx.media3.exoplayer.RendererCapabilities.Capabilities) Nullable(androidx.annotation.Nullable) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Nullable(androidx.annotation.Nullable)

Example 7 with MappedTrackInfo

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;
}
Also used : SparseArray(android.util.SparseArray) TrackGroupArray(androidx.media3.common.TrackGroupArray) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Pair(android.util.Pair)

Example 8 with MappedTrackInfo

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();
}
Also used : TrackGroup(androidx.media3.common.TrackGroup) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) AttrRes(androidx.annotation.AttrRes) Arrays(java.util.Arrays) MappedTrackInfo(androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo) DefaultTrackSelector(androidx.media3.exoplayer.trackselection.DefaultTrackSelector) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) AttributeSet(android.util.AttributeSet) View(android.view.View) Assertions(androidx.media3.common.util.Assertions) SelectionOverride(androidx.media3.exoplayer.trackselection.DefaultTrackSelector.SelectionOverride) UnstableApi(androidx.media3.common.util.UnstableApi) LayoutInflater(android.view.LayoutInflater) TrackGroupArray(androidx.media3.common.TrackGroupArray) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull) Format(androidx.media3.common.Format) SparseArray(android.util.SparseArray) C(androidx.media3.common.C) List(java.util.List) Nullable(androidx.annotation.Nullable) CheckedTextView(android.widget.CheckedTextView) Comparator(java.util.Comparator) SelectionOverride(androidx.media3.exoplayer.trackselection.DefaultTrackSelector.SelectionOverride)

Example 9 with MappedTrackInfo

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();
}
Also used : MappedTrackInfo(androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo) TrackGroup(androidx.media3.common.TrackGroup) CheckedTextView(android.widget.CheckedTextView)

Example 10 with MappedTrackInfo

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));
            }
        }
    }
}
Also used : SelectionOverride(androidx.media3.exoplayer.trackselection.DefaultTrackSelector.SelectionOverride) MappedTrackInfo(androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo) CheckedTextView(android.widget.CheckedTextView)

Aggregations

TrackGroupArray (androidx.media3.common.TrackGroupArray)11 TrackGroup (androidx.media3.common.TrackGroup)8 MappedTrackInfo (androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo)8 SuppressLint (android.annotation.SuppressLint)5 Point (android.graphics.Point)5 Nullable (androidx.annotation.Nullable)5 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)5 Capabilities (androidx.media3.exoplayer.RendererCapabilities.Capabilities)4 DefaultTrackSelector (androidx.media3.exoplayer.trackselection.DefaultTrackSelector)4 CheckedTextView (android.widget.CheckedTextView)3 TrackSelection (androidx.media3.common.TrackSelection)3 TracksInfo (androidx.media3.common.TracksInfo)3 SelectionOverride (androidx.media3.exoplayer.trackselection.DefaultTrackSelector.SelectionOverride)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Pair (android.util.Pair)2 SparseArray (android.util.SparseArray)2 Format (androidx.media3.common.Format)2 TrackSelectionOverride (androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride)2 RendererConfiguration (androidx.media3.exoplayer.RendererConfiguration)2