【问题标题】:Make TvInputService display an overlay使 TvInputService 显示覆盖
【发布时间】:2018-01-23 10:19:43
【问题描述】:

我正在尝试编写一个最简单的 TvInputService,它将使用TIF Companion Library 显示覆盖。

Live Channels 应用程序已经识别出我在 EpgSyncJobService 子类中声明的频道 Simple ChannelMy Program 显示在 Live Channels 应用程序的 EPG 中,与当前呈现的一样。 但是,我只能看到蓝色微调器,好像频道没有“调整”。

我做错了什么?

public class MyTvInputService extends BaseTvInputService {
        @Override
    public final BaseTvInputService.Session onCreateSession(String inputId) {
        BaseTvInputService.Session session = new MyTvInputSession(this, inputId);
        session.setOverlayViewEnabled(true);
        return super.sessionCreated(session);
    }

    class MyTvInputSession extends BaseTvInputService.Session {
        public MyTvInputSession(Context context, String inputId) {
            super(context, inputId);
        }

        @Override
        public View onCreateOverlayView() {
            mTextView = new TextView(MyTvInputService.this);
            mTextView.setText("This is an example overlay");
            mTextView.setTextColor(Color.RED);
            mTextView.setVisibility(View.VISIBLE);
            mTextView.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            return mTextView;
        }

        @Override
        public boolean onPlayProgram(Program program, long startPosMs) {
            return true;
        }

        @Override
        public boolean onPlayRecordedProgram(RecordedProgram recordedProgram) {
            return true;
        }

        @Override
        public void onSetCaptionEnabled(boolean enable) {}

        @Override
        public TvPlayer getTvPlayer() { return null; }
    }
    private TextView mTextView;
}

【问题讨论】:

  • 你好,我正在尝试使用 TIF 构建一个 android 电视应用程序,我使用 developer.android.com/training/tv/tif/tvinput 上的文档作为指导,我有 2 个问题,1) 服务没有绑定自动和 2)即使我将 Android 电视与 HDMI 连接并启用了 HDMI CEC,也永远不会创建会话,有什么线索我可能做错了吗?
  • 这在很多方面都很棘手。请确保您已为您的服务提供 android.permission.BIND_TV_INPUT android:permission 和适当的意图过滤器。另一个常见问题破坏了某些设备上的 TV App 实现。请尝试使用 google.android.permission.BIND_TV_INPUT(注意 google 前缀)。你也应该先在模拟器上试用一下。这是损坏最少的平台。如果您提出 SO 问题,我很乐意提供帮助。
  • 我发现该服务没有自动绑定,因为该服务仅在打开直播频道应用程序时才绑定,但此应用程序适用于整个应用程序,而不是直播频道应用程序,在此如果我基本上剩下第二个问题,有什么线索吗?

标签: android-tv


【解决方案1】:

根据TvInputService.Session.notifyVideoAvailable() documentation

电视输入服务必须在收到内容后立即调用此方法 渲染到其表面上即可查看。这种方法必须 每次调用 onTune(Uri) 时都会调用。

所以在BaseTvInputService.Session.onTune(Uri)方法覆盖中调用notifyVideoAvailable()就足够了,像这样:

@Override
public boolean onTune(Uri channelUri) {
    notifyVideoAvailable();
    return true;
}

我必须说,使用 TV Companion Library 的 BaseTvInputService 比使用裸 TvInputService 更难发现此类问题,因为 onTune() 方法在 BaseTvInputService.Session 中是非抽象的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    • 2016-03-21
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 2015-10-06
    • 2021-09-12
    相关资源
    最近更新 更多