По умолчанию TrackSelectionDialog печатаю их, скажем, в случайном порядке. Я хочу изменить их порядок с минимального на максимальный.
Итак, у меня есть это в моем 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 overrides,
@Nullable Comparator trackFormatComparator,
@Nullable TrackSelectionListener listener) {
this.mappedTrackInfo = mappedTrackInfo;
this.rendererIndex = rendererIndex;
this.isDisabled = isDisabled;
if (trackFormatComparator == null)
this.trackInfoComparator = null;
else
this.trackInfoComparator = new Comparator() {
@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();
}
Код: Выделить всё
public void setTrackFormatComparator(@Nullable Comparator trackFormatComparator) {
TrackSelectionDialog.trackFormatComparator = trackFormatComparator;
}
Код: Выделить всё
trackSelectionView.init(
mappedTrackInfo,
rendererIndex,
isDisabled,
overrides,
trackFormatComparator /*null*/,
/* listener= */ this);
Код: Выделить всё
TrackSelectionDialog trackSelectionDialog = TrackSelectionDialog.createForTrackSelector(
trackSelector, dismissedDialog -> isShowingTrackSelectionDialog = false);
trackSelectionDialog.setTrackFormatComparator((o1, o2) -> Math.max(o1.height, o2.height));
trackSelectionDialog.show(getSupportFragmentManager(), null);
Что не так с моим кодом или какую часть кода я забыл?
Подробнее здесь: https://stackoverflow.com/questions/773 ... ot-working
Мобильная версия