我打印视频轨道的用户在“高度”+“p”格式。默认情况下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<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();
}
字符串
我把它添加到TrackSelectionDialog
中:
public void setTrackFormatComparator(@Nullable Comparator<Format> trackFormatComparator) {
TrackSelectionDialog.trackFormatComparator = trackFormatComparator;
}
型
并取消注解TrackSelectionViewFragment
的onCreateView
中的trackFormatComparator
(在TrackSelectionDialog
类中):
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);
型
但什么也没有发生。视频轨道仍然排序默认。
我的代码有什么问题,或者我忘记了代码的哪一部分?
1条答案
按热度按时间dy1byipe1#
Java Android视频问题
**Comparator:**您编码的
(o1, o2) -> Math.max(o1.height, o2.height)
不正确。此comparator
实际上提供了比较两种格式时的最大高度,但这不是比较器的正确输出。comparator
应该给予指示顺序的integer
,例如less than
为负数equal
为零,greater than
为正数。确保
TrackSelectionDialog
正确传递trackFormatComparator
,并且正确使用。关于这一点,将代码行替换为:
字符串
现在,
Comparator
应该根据高度比较返回一个整数,这是预期的结果。