如何通过强制转换控制界面捕获UIMediaController点击

mwi*_*rek 8 android google-cast

我在我的应用程序中构建了一个完美运行的自定义投射发送器 - 我需要添加的唯一功能是收听"播放/暂停"和"跳过"按钮的方式,但Google的文档(据我所知)能够搜索)没有给出任何线索,并且在添加高级演员功能中显示的功能后,文档无法正常工作:

CastMediaOptions castMediaOptions = new CastMediaOptions.Builder()
     .setMediaIntentReceiverClassName(CastIntentReceiver.class.getName())
     .build();

return new CastOptions.Builder()
        .setReceiverApplicationId(context.getString(R.string.cast_id))
        .setCastMediaOptions(castMediaOptions)
        .build();
Run Code Online (Sandbox Code Playgroud)

我有一个CastIntentReceiver扩展MediaIntentReceiver,它CastOptionsProvider在清单中和引用中引用.

public class CastIntentReceiver extends MediaIntentReceiver {

    public static String TAG = "CastIntentReceiver";

    public CastIntentReceiver() {
        Log.i(TAG, "CastIntentReceiver: Constructed!");
    }
    ...
    // The rest of the Override methods don't do anything

}
Run Code Online (Sandbox Code Playgroud)

接收器正在工作,因为日志打印正在工作,但没有调用任何覆盖方法(无日志打印).

以下是我实施的一些其他详细信息:

所有的转换函数都在两个独立的类中,CastManager(控制器)和CastControls片段(视图),它被添加到MainActivity View的基础(类似于YouTube).还有接口可以触发这两个类之间的事物.

在CastManager中,我设置UIMediaController并绑定视图:

View view = CastingBridge.CAST_CONTROLS_VIEW.findViewById(R.id.cast_drawer_controls);

uiMediaController = new UIMediaController(activity);
SeekBar seekBar = (SeekBar) view.findViewById(R.id.cast_control_seek_bar);
TextView start = (TextView) view.findViewById(R.id.cast_control_time_start);
TextView end = (TextView) view.findViewById(R.id.cast_control_time_end);
ImageButton playPauseButton = (ImageButton) view.findViewById(R.id.cast_control_play_pause);
ImageButton rewindButton = (ImageButton) view.findViewById(R.id.cast_control_rewind);
ImageButton forwardButton = (ImageButton) view.findViewById(R.id.cast_control_forward);
ImageButton stopButton = (ImageButton) view.findViewById(R.id.cast_control_stop);
ProgressBar loadingSpinner = (ProgressBar) view.findViewById(R.id.cast_control_loading);
Run Code Online (Sandbox Code Playgroud)

如前所述,所有这些工作都应该如此,但我需要监听(捕获)触摸/点击事件,以便在视频暂停或停止时,我可以保存当前的手表长度以便恢复.

我如何实现MediaIntentReceiver监听这些事件?我已经尝试将单击侦听器添加到各个视图,但正如预期的那样,@Override onClick删除了最初的预期功能.

文件规定了什么似乎是我需要的方法,但如何引用?

我还尝试添加唯一可用的侦听器UIMediaController:

uiMediaController.setPostRemoteMediaClientListener(new RemoteMediaClient.Listener() {
    @Override
    public void onStatusUpdated() {
        Log.i(TAG, "onStatusUpdated: Status Updated");
    }
});
Run Code Online (Sandbox Code Playgroud)

然而,这没有做任何事情,因为该onStatusUpdated方法不提供任何参数.

任何人都可以帮我解释一下吗?我一直在尝试不同的事情,现在搜索几天,所以有时间寻求帮助.

谢谢!

Ali*_*daf 4

您定义的接收器(以及一般的 MediaIntentReceiver)用于处理来自通知、锁定屏幕和投射对话框的操作;因此,自定义一个会影响从这些地方启动时的行为。如果您使用 UIMediaController,那么您需要使用onSendingRemoteMediaRequest()在用户与这些控件交互时收到通知。