Android TV-leanback库如何向VideoSupportFragmentGlueHost

时间:2018-12-05 08:01:08

标签: android android-tv

我正在使用leanback-v17:27.1.0库,我尝试自定义VideoSupportFragmentGlueHost,我想在此处添加更多按钮,例如重复或下一个按钮 enter image description here 我试图使用leanback.app.PlaybackOverlayFragment但在leanback-v17:27中没有像本教程这样的PlaybackOverlayFragment类 http://corochann.com/android-tv-application-hands-on-tutorial-7-159.html#PlaybackOverlayFragment 有人可以帮助我向此VideoSupportFragmentGlueHost添加更多按钮

 public void initData(MovieSampleResult mObject)
{
    try {
        VideoSupportFragmentGlueHost glueHost =
                new VideoSupportFragmentGlueHost(PlayFullScreenVideoFragment.this);
        MediaPlayerAdapter playerAdapter = new MediaPlayerAdapter(getContext());
        playerAdapter.setRepeatAction(PlaybackControlsRow.RepeatAction.INDEX_NONE);
        mTransportControlGlue = new PlaybackTransportControlGlue<>(getContext(), playerAdapter);
        mTransportControlGlue.setHost(glueHost);
        mTransportControlGlue.setTitle(mObject.getName());
        //mTransportControlGlue.setSubtitle(mObject.getDescription());
        playerAdapter.setDataSource(Uri.parse(mObject.getVideo()));
        Log.e("TAG PLAY FULL",mObject.getVideo());
        MyTrackApplication myTrackApplication = MyTrackApplication.getInstance();
        myTrackApplication.trackScreenView(TAGSCREEN,
                mObject.getName(),
                "Watch Video on FullScreen Mode",0);
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(TAG,e.getMessage());
    }
}

1 个答案:

答案 0 :(得分:0)

如果要向默认的传输控件布局添加其他操作,则需要扩展PlaybackTransportControlGlue类并覆盖添加操作的方法。

下面是一个示例,显示了如何添加其他主要操作(在搜索栏上方的第一行)以跳至下一个内容,以及如何添加辅助动作(在搜索栏下方)以启用隐藏式字幕。本示例使用MediaPlayerAdapter类,因为这是您在问题中使用的类,但是它可以与任何PlayerAdapter实现一起使用。

public class VideoPlayerGlue extends PlaybackTransportControlGlue<MediaPlayerAdapter> {

    private PlaybackControlsRow.SkipNextAction skipNextAction;
    private PlaybackControlsRow.ClosedCaptioningAction closedCaptioningAction;

    public VideoPlayerGlue(Context context, MediaPlayerAdapter impl) {
        super(context, impl);

        closedCaptioningAction = new PlaybackControlsRow.ClosedCaptioningAction(context);
        skipNextAction = new PlaybackControlsRow.SkipNextAction(context);
    }

    @Override
    protected void onCreatePrimaryActions(ArrayObjectAdapter primaryActionsAdapter) {
        super.onCreatePrimaryActions(primaryActionsAdapter); // Adds play/pause first.
        primaryActionsAdapter.add(skipNextAction); // Adds skip next second. Order matters.
    }

    @Override
    protected void onCreateSecondaryActions(ArrayObjectAdapter secondaryActionsAdapter) {
        secondaryActionsAdapter.add(closedCaptioningAction); // Adds CC to row below seek bar.
    }

    @Override
    public void onActionClicked(Action action) {
        // Handle your action clicks here to allow them to interface with
        // the player and/or the PlayerAdapter.

        super.onActionClicked(action); // Allows for built-in play/pause and seek bar clicks.
    }
}