android ExoPlayer TrackSelectionDialog比较器不工作

cl25kdpy  于 2023-11-15  发布在  Android
关注(0)|答案(1)|浏览(97)

我打印视频轨道的用户在“高度”+“p”格式。默认情况下TrackSelectionDialog打印他们让我们说,在随机顺序。我想重新排序他们从最小到最大。
所以我在TrackSelectionViewinit中有这个:

/**
 * 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;
    }


并取消注解TrackSelectionViewFragmentonCreateView中的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);


但什么也没有发生。视频轨道仍然排序默认。
我的代码有什么问题,或者我忘记了代码的哪一部分?

dy1byipe

dy1byipe1#

Java Android视频问题

**Comparator:**您编码的(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应该根据高度比较返回一个整数,这是预期的结果。

相关问题