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();
}
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();
}
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);
}
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;
}
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);
}
Aggregations