gpt4 book ai didi

安卓电视 : PlaybackControlsRow action long press

转载 作者:行者123 更新时间:2023-11-30 00:39:40 26 4
gpt4 key购买 nike

我正在尝试使用 PlaybackControlsRow 使用 Android TVLeanback 库 实现快进和快退操作,但是我可以找不到任何方法来检测对这些按钮的长按。我目前的实现很简单,一次点击只搜索10秒:

private void setupRows() {
final ClassPresenterSelector ps = new ClassPresenterSelector();
final PlaybackControlsRowPresenter playbackControlsRowPresenter =
new PlaybackControlsRowPresenter(new DescriptionPresenter());

playbackControlsRowPresenter.setOnActionClickedListener(action -> {
if (action.getId() == playPauseAction.getId()) {
togglePlayback(playPauseAction.getIndex() == PlayPauseAction.PLAY);
} else if (action.getId() == fastForwardAction.getId()) {
fastForward();
return;
} else if (action.getId() == rewindAction.getId()) {
rewind();
return;
}
if (action instanceof PlaybackControlsRow.MultiAction) {
((PlaybackControlsRow.MultiAction) action).nextIndex();
notifyChanged(action);
}
});

ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
rowsAdapter = new ArrayObjectAdapter(ps);

updatePlaybackControlsRow();

setAdapter(rowsAdapter);
}

private void fastForward() {
((PlaybackActivity) getActivity()).onFragmentFastForward();

final int currentTime = ((PlaybackActivity) getActivity()).getPosition();
playbackControlsRow.setCurrentTime(currentTime);
}

private void rewind() {
((PlaybackActivity) getActivity()).onFragmentRewind();

final int currentTime = ((PlaybackActivity) getActivity()).getPosition();
playbackControlsRow.setCurrentTime(currentTime);
}

PlaybackActivity中:

public void onFragmentFastForward() {
// Fast forward 10 seconds.
videoView.seekTo(videoView.getCurrentPosition() + (10 * 1000));
}

public void onFragmentRewind() {
videoView.seekTo(videoView.getCurrentPosition() - (10 * 1000));
}

是否可以在长按操作时实现快进和快退,例如操作按钮上的上键/下键事件?

最佳答案

在寻找其他解决方案之后,似乎 PlaybackControlsRowPresenter 的设计方式应该是不应该长按,而是通过点击快进/快退按钮的次数来增加/减少速度.从PlaybackControlsRowPresenter.FastForwardActionPlaybackControlsRowPresenter.RewindAction类的内部构造函数实现可以清楚的看出:

/**
* Constructor
* @param context Context used for loading resources.
* @param numSpeeds Number of supported fast forward speeds.
*/
public FastForwardAction(Context context, int numSpeeds) {

因此,我现在的解决方案是通过每次单击快进/快退按钮(默认情况下在 UI 上完成)来增加/减少速度。之后,当我点击播放时 - 它只是从寻找的点恢复视频。

UPDATE(更新部分代码):

    private void setupRows() {
final ClassPresenterSelector ps = new ClassPresenterSelector();
final PlaybackControlsRowPresenter playbackControlsRowPresenter =
new PlaybackControlsRowPresenter(new DescriptionPresenter());

playbackControlsRowPresenter.setOnActionClickedListener(action -> {
if (action.getId() == playPauseAction.getId()) {
togglePlayback(playPauseAction.getIndex() == PlayPauseAction.PLAY);
((PlaybackControlsRow.MultiAction) action).nextIndex();
notifyChanged(action);
} else if (action.getId() == fastForwardAction.getId()) {
if (currentSpeed <= MAX_SPEED) {
currentSpeed++;

showTogglePlayback(false, true);

if (currentSpeed < 0) {
prevRewind();
} else if (currentSpeed > 0) {
nextFastForward();
} else {
currentSpeed++;
prevRewind();
nextFastForward();
}

((PlaybackActivity) getActivity()).seek(currentSpeed);
}
} else if (action.getId() == rewindAction.getId()) {
if (currentSpeed >= MIN_SPEED) {
currentSpeed--;

showTogglePlayback(false, true);

if (currentSpeed > 0) {
prevFastForward();
} else if (currentSpeed < 0) {
nextRewind();
} else {
currentSpeed--;
prevFastForward();
nextRewind();
}

((PlaybackActivity) getActivity()).seek(currentSpeed);
}
} else if (action.getId() == R.id.lb_control_picture_in_picture &&
PlaybackActivity.supportsPictureInPicture(getActivity())) {
getActivity().enterPictureInPictureMode();
}
});

ps.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
ps.addClassPresenter(ListRow.class, new ListRowPresenter());
rowsAdapter = new ArrayObjectAdapter(ps);

updatePlaybackControlsRow();

setAdapter(rowsAdapter);
}

private void prevFastForward() {
fastForwardAction.setIndex(fastForwardAction.getIndex() - 1);
notifyChanged(fastForwardAction);
}

private void nextFastForward() {
fastForwardAction.nextIndex();
notifyChanged(fastForwardAction);
}

private void prevRewind() {
rewindAction.setIndex(rewindAction.getIndex() - 1);
notifyChanged(rewindAction);
}

private void nextRewind() {
rewindAction.nextIndex();
notifyChanged(rewindAction);
}

关于安卓电视 : PlaybackControlsRow action long press,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42739106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com