使 TvInputService 显示覆盖

Make TvInputService display an overlay

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

Live Channels 应用程序已经识别出我在 EpgSyncJobService 子类中声明的频道 Simple ChannelMy Program 在实时频道应用程序的 EPG 中显示为当前呈现的一个。 但是,我只能看到蓝色的旋转器,好像频道没有 "tune".

我做错了什么?

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;
}

根据TvInputService.Session.notifyVideoAvailable() documentation

The TV input service must call this method as soon as the content rendered onto its surface is ready for viewing. This method must be called each time onTune(Uri) is called.

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

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

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