提问人:danyapd 提问时间:10/31/2023 最后编辑:danyapd 更新时间:11/9/2023 访问量:78
ExoPlayer TrackSelectionDialog 比较器不工作
ExoPlayer TrackSelectionDialog comparator not working
问:
我正在以“height”+“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;
}
并在 of (在课堂上) 取消注释:trackFormatComparator
onCreateView
TrackSelectionViewFragment
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赞
AztecCodes
11/9/2023
#1
Java Android 视频问题
比较仪:您编码的不正确。这实际上提供了比较两种格式时的最大高度,但这不是比较器的正确输出。A 应该给出一个指示顺序的 a,比如 的负数表示 的零和 的正数。Comparator Logic
(o1, o2) -> Math.max(o1.height, o2.height)
comparator
comparator
integer
less than
equal
greater than
确保 得到正确传递,并且也被正确使用。TrackSelectionDialog
trackFormatComparator
关于这一点,将代码行替换为:
// Fixed the comparator logic code for sorting by height
trackSelectionDialog.setTrackFormatComparator((o1, o2) -> Integer.compare(o1.height, o2.height));
现在,您应该根据高度比较返回一个整数,这是预期的。Comparator
评论
0赞
danyapd
11/14/2023
效果很好。
评论