I am printing video tracks to user in "height" + "p" format.
By default TrackSelectionDialog printing them let's say in random order. I want to reorder them from min to max.
So I have this in my TrackSelectionView 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;
if (trackFormatComparator == null)
this.trackInfoComparator = null;
else
this.trackInfoComparator = new Comparator<TrackInfo>() {
@Override
public int compare(TrackInfo o1, TrackInfo o2) {
return 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();
}
I've add this to my TrackSelectionDialog:
public void setTrackFormatComparator(@Nullable Comparator<Format> trackFormatComparator) {
TrackSelectionDialog.trackFormatComparator = trackFormatComparator;
}
and uncomment trackFormatComparator in onCreateView of TrackSelectionViewFragment (in TrackSelectionDialog class):
trackSelectionView.init(
mappedTrackInfo,
rendererIndex,
isDisabled,
overrides,
trackFormatComparator /*null*/,
/* listener= */ this);
Then in my player activity I wrote this to sort video tracks by frame height:
TrackSelectionDialog trackSelectionDialog = TrackSelectionDialog.createForTrackSelector(
trackSelector, dismissedDialog -> isShowingTrackSelectionDialog = false);
trackSelectionDialog.setTrackFormatComparator((o1, o2) -> Math.max(o1.height, o2.height));
trackSelectionDialog.show(getSupportFragmentManager(), null);
But nothing happens. Video tracks still sorted default.
What is wrong with my code or what part of code I've forgot?