Search in sources :

Example 11 with SelectionOverride

use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride in project ExoPlayer by google.

the class DownloadHelper method addTrackSelectionForSingleRenderer.

/**
 * Convenience method to add a selection of tracks to be downloaded for a single renderer. Must
 * not be called until after preparation completes.
 *
 * @param periodIndex The period index the track selection is added for.
 * @param rendererIndex The renderer index the track selection is added for.
 * @param trackSelectorParameters The {@link DefaultTrackSelector.Parameters} to obtain the new
 *     selection of tracks.
 * @param overrides A list of {@link SelectionOverride SelectionOverrides} to apply to the {@code
 *     trackSelectorParameters}. If empty, {@code trackSelectorParameters} are used as they are.
 */
public void addTrackSelectionForSingleRenderer(int periodIndex, int rendererIndex, DefaultTrackSelector.Parameters trackSelectorParameters, List<SelectionOverride> overrides) {
    assertPreparedWithMedia();
    DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon();
    for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) {
        builder.setRendererDisabled(/* rendererIndex= */
        i, /* disabled= */
        i != rendererIndex);
    }
    if (overrides.isEmpty()) {
        addTrackSelection(periodIndex, builder.build());
    } else {
        TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex);
        for (int i = 0; i < overrides.size(); i++) {
            builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i));
            addTrackSelection(periodIndex, builder.build());
        }
    }
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector)

Example 12 with SelectionOverride

use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride in project ExoPlayer by google.

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

Example 13 with SelectionOverride

use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride in project ExoPlayer by google.

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(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo) CheckedTextView(android.widget.CheckedTextView)

Example 14 with SelectionOverride

use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride in project ExoPlayer by google.

the class TrackSelectionView method updateViewStates.

private void updateViewStates() {
    disableView.setChecked(isDisabled);
    defaultView.setChecked(!isDisabled && overrides.size() == 0);
    for (int i = 0; i < trackViews.length; i++) {
        SelectionOverride override = overrides.get(i);
        for (int j = 0; j < trackViews[i].length; j++) {
            if (override != null) {
                TrackInfo trackInfo = (TrackInfo) Assertions.checkNotNull(trackViews[i][j].getTag());
                trackViews[i][j].setChecked(override.containsTrack(trackInfo.trackIndex));
            } else {
                trackViews[i][j].setChecked(false);
            }
        }
    }
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Aggregations

SelectionOverride (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride)7 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)6 CheckedTextView (android.widget.CheckedTextView)4 MappedTrackInfo (com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)4 SelectionOverride (com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride)4 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)4 Format (com.google.android.exoplayer2.Format)3 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)3 Test (org.junit.Test)3 SuppressLint (android.annotation.SuppressLint)2 Pair (android.util.Pair)2 Nullable (androidx.annotation.Nullable)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 FixedTrackSelection (com.google.android.exoplayer2.trackselection.FixedTrackSelection)2 RandomTrackSelection (com.google.android.exoplayer2.trackselection.RandomTrackSelection)2 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)2 Context (android.content.Context)1 TypedArray (android.content.res.TypedArray)1 AttributeSet (android.util.AttributeSet)1 SparseArray (android.util.SparseArray)1