【问题标题】:Android TV - leanback library how to add more button to VideoSupportFragmentGlueHostAndroid TV-leanback 库如何向 VideoSupportFragmentGlueHost 添加更多按钮
【发布时间】:2018-12-05 08:01:07
【问题描述】:

我正在使用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());
    }
}

【问题讨论】:

    标签: android android-tv


    【解决方案1】:

    如果您想向默认传输控件布局添加其他操作,则需要扩展 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.
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多