Search in sources :

Example 1 with SelectionOverride

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

the class TrackSelectionHelper method onClick.

// View.OnClickListener
@Override
public void onClick(View view) {
    if (view == disableView) {
        isDisabled = true;
        override = null;
    } else if (view == defaultView) {
        isDisabled = false;
        override = null;
    } else if (view == enableRandomAdaptationView) {
        setOverride(override.groupIndex, override.tracks, !enableRandomAdaptationView.isChecked());
    } else {
        isDisabled = false;
        @SuppressWarnings("unchecked") Pair<Integer, Integer> tag = (Pair<Integer, Integer>) view.getTag();
        int groupIndex = tag.first;
        int trackIndex = tag.second;
        if (!trackGroupsAdaptive[groupIndex] || override == null || override.groupIndex != groupIndex) {
            override = new SelectionOverride(FIXED_FACTORY, groupIndex, trackIndex);
        } else {
            // The group being modified is adaptive and we already have a non-null override.
            boolean isEnabled = ((CheckedTextView) view).isChecked();
            int overrideLength = override.length;
            if (isEnabled) {
                // Remove the track from the override.
                if (overrideLength == 1) {
                    // The last track is being removed, so the override becomes empty.
                    override = null;
                    isDisabled = true;
                } else {
                    setOverride(groupIndex, getTracksRemoving(override, trackIndex), enableRandomAdaptationView.isChecked());
                }
            } else {
                // Add the track to the override.
                setOverride(groupIndex, getTracksAdding(override, trackIndex), enableRandomAdaptationView.isChecked());
            }
        }
    }
    // Update the views with the new state.
    updateViews();
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride) CheckedTextView(android.widget.CheckedTextView) SuppressLint(android.annotation.SuppressLint) Pair(android.util.Pair) SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride)

Example 2 with SelectionOverride

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

the class TrackSelectionHelper method onClick.

// View.OnClickListener
@Override
public void onClick(View view) {
    isDisabled = false;
    @SuppressWarnings("unchecked") Pair<Integer, Integer> tag = (Pair<Integer, Integer>) view.getTag();
    int groupIndex = tag.first;
    int trackIndex = tag.second;
    if (!trackGroupsAdaptive[groupIndex] || override == null || override.groupIndex != groupIndex) {
        override = new SelectionOverride(FIXED_FACTORY, groupIndex, trackIndex);
    } else {
        // The group being modified is adaptive and we already have a non-null override.
        boolean isEnabled = ((CheckedTextView) view).isChecked();
        int overrideLength = override.length;
        if (isEnabled) {
            // Remove the track from the override.
            if (overrideLength == 1) {
                // The last track is being removed, so the override becomes empty.
                override = null;
                isDisabled = true;
            } else {
                setOverride(groupIndex, getTracksRemoving(override, trackIndex), false);
            }
        } else {
            // Add the track to the override.
            setOverride(groupIndex, getTracksAdding(override, trackIndex), false);
        }
    }
    // Update the views with the new state.
    updateViews();
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride) CheckedTextView(android.widget.CheckedTextView) SuppressLint(android.annotation.SuppressLint) Pair(android.util.Pair) SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride)

Example 3 with SelectionOverride

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

the class TrackSelectionHelper method setOverride.

private void setOverride(int group, int[] tracks, boolean enableRandomAdaptation) {
    TrackSelection.Factory factory = tracks.length == 1 ? FIXED_FACTORY : (enableRandomAdaptation ? RANDOM_FACTORY : adaptiveVideoTrackSelectionFactory);
    override = new SelectionOverride(factory, group, tracks);
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.MappingTrackSelector.SelectionOverride) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) FixedTrackSelection(com.google.android.exoplayer2.trackselection.FixedTrackSelection) RandomTrackSelection(com.google.android.exoplayer2.trackselection.RandomTrackSelection)

Example 4 with SelectionOverride

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

the class TrackSelectionDialog method createForTrackSelector.

/**
 * Creates a dialog for a given {@link DefaultTrackSelector}, whose parameters will be
 * automatically updated when tracks are selected.
 *
 * @param trackSelector The {@link DefaultTrackSelector}.
 * @param onDismissListener A {@link DialogInterface.OnDismissListener} to call when the dialog is
 *     dismissed.
 */
public static TrackSelectionDialog createForTrackSelector(DefaultTrackSelector trackSelector, DialogInterface.OnDismissListener onDismissListener) {
    MappedTrackInfo mappedTrackInfo = Assertions.checkNotNull(trackSelector.getCurrentMappedTrackInfo());
    TrackSelectionDialog trackSelectionDialog = new TrackSelectionDialog();
    DefaultTrackSelector.Parameters parameters = trackSelector.getParameters();
    trackSelectionDialog.init(/* titleId= */
    R.string.track_selection_title, mappedTrackInfo, /* initialParameters = */
    parameters, /* allowAdaptiveSelections= */
    true, /* allowMultipleOverrides= */
    false, /* onClickListener= */
    (dialog, which) -> {
        DefaultTrackSelector.ParametersBuilder builder = parameters.buildUpon();
        for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
            builder.clearSelectionOverrides(/* rendererIndex= */
            i).setRendererDisabled(/* rendererIndex= */
            i, trackSelectionDialog.getIsDisabled(/* rendererIndex= */
            i));
            List<SelectionOverride> overrides = trackSelectionDialog.getOverrides(/* rendererIndex= */
            i);
            if (!overrides.isEmpty()) {
                builder.setSelectionOverride(/* rendererIndex= */
                i, mappedTrackInfo.getTrackGroups(/* rendererIndex= */
                i), overrides.get(0));
            }
        }
        trackSelector.setParameters(builder);
    }, onDismissListener);
    return trackSelectionDialog;
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Example 5 with SelectionOverride

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

the class DefaultTrackSelector method getLegacyRendererOverride.

// Calling deprecated getSelectionOverride.
@SuppressWarnings("deprecation")
private ExoTrackSelection.@NullableType Definition getLegacyRendererOverride(MappedTrackInfo mappedTrackInfo, Parameters params, int rendererIndex) {
    TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
    @Nullable SelectionOverride override = params.getSelectionOverride(rendererIndex, rendererTrackGroups);
    if (override == null) {
        return null;
    }
    return new ExoTrackSelection.Definition(rendererTrackGroups.get(override.groupIndex), override.tracks, override.type);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Nullable(androidx.annotation.Nullable)

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