我有一个简单的Android TV leanback应用程序,可以显示视频。视频播放器工作正常并显示必要的控件。但是,我想在PlaybackControlsRow的右侧添加视频的总持续时间,但不知道如何。我正在使用此代码来设置PlaybackControlRow
private void addPlaybackControlsRow() {
/* movieItem data must have newly allocated area, do not refer existing movie (ex. mItems.get(0))
since this item will be overwritten later */
Movie movieItem = new Movie();
mPlaybackControlsRow = new PlaybackControlsRow(movieItem);
mRowsAdapter.add(mPlaybackControlsRow);
ControlButtonPresenterSelector presenterSelector = new ControlButtonPresenterSelector();
mPrimaryActionsAdapter = new ArrayObjectAdapter(presenterSelector);
mSecondaryActionsAdapter = new ArrayObjectAdapter(presenterSelector);
mPlaybackControlsRow.setPrimaryActionsAdapter(mPrimaryActionsAdapter);
mPlaybackControlsRow.setSecondaryActionsAdapter(mSecondaryActionsAdapter);
Activity activity = getActivity();
mPlayPauseAction = new PlaybackControlsRow.PlayPauseAction(activity);
mRepeatAction = new PlaybackControlsRow.RepeatAction(activity);
mThumbsUpAction = new PlaybackControlsRow.ThumbsUpAction(activity);
mThumbsDownAction = new PlaybackControlsRow.ThumbsDownAction(activity);
mShuffleAction = new PlaybackControlsRow.ShuffleAction(activity);
mSkipNextAction = new PlaybackControlsRow.SkipNextAction(activity);
mSkipPreviousAction = new PlaybackControlsRow.SkipPreviousAction(activity);
mFastForwardAction = new PlaybackControlsRow.FastForwardAction(activity);
mRewindAction = new PlaybackControlsRow.RewindAction(activity);
/* PrimaryAction setting */
mPrimaryActionsAdapter.add(mSkipPreviousAction);
mPrimaryActionsAdapter.add(mRewindAction);
mPrimaryActionsAdapter.add(mPlayPauseAction);
mPrimaryActionsAdapter.add(mFastForwardAction);
mPrimaryActionsAdapter.add(mSkipNextAction);
}
我设置了当前时间,并尝试设置总时间,如下所示:
int currentTime = mPlaybackController.getCurrentPosition();
int totalTime = mPlaybackControlsRow.getTotalTime();
mPlaybackControlsRow.setCurrentTime(currentTime);
mPlaybackControlsRow.setTotalTime(totalTime);
如您所见,我无法获得 PlaybackControlsRow 右侧的总时间。我该如何解决这个问题?
答案 0 :(得分:0)
尝试getDuration()
和setDuration(long)
,因为{C}级别已弃用getTotalTime()
和setTotalTime()
。
答案 1 :(得分:0)
正如用户@Ewald所评论的那样,我忘了通知mRowsAdapter
对象。如果您使用的是25级或更低级别的API,则在setTotalTime(totalTime)
对象上调用PlaybackControlsRow
时,必须通知适配器以查看更改。以下是setTotalTime
方法
设置播放控件行的总时间(以毫秒为单位)。
如果在将行绑定到视图后设置,则必须是适配器 通知此行已更改。
因此,我像这样通知了适配器
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
现在我得到了总时间。希望这有助于某人。