【问题标题】:How to capture UIMediaController clicks via casting control interface如何通过投射控制界面捕获 UIMediaController 点击
【发布时间】:2016-12-05 14:21:17
【问题描述】:

我在我的应用程序中构建了一个自定义投射发送器,它运行良好 - 我需要添加的唯一功能是监听“播放/暂停”和“跳过”按钮的方法,但 Google 的文档(就我已经能够搜索到)没有给出任何线索,并且添加了Advanced Cast Features Docs中显示的功能后不起作用:

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

return new CastOptions.Builder()
        .setReceiverApplicationId(context.getString(R.string.cast_id))
        .setCastMediaOptions(castMediaOptions)
        .build();

我有一个 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

}

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

以下是关于我的实现的一些额外细节:

所有转换函数都在两个单独的类中,即 CastManager(控制器)和 CastControls 片段(视图),后者添加到 MainActivity 视图的基础(类似于 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);

如前所述,所有这些工作都应有尽有,但我需要监听(捕获)触摸/点击事件,以便在视频暂停或停止时,我可以保存当前的观看时长以用于恢复。

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

documentation 指定了我似乎需要的方法,但是如何引用它?

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

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

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

谁能帮我解释一下这个?我一直在尝试不同的东西并搜索了几天,所以是时候寻求帮助了。

谢谢!

【问题讨论】:

    标签: android google-cast


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复。我已经实现了这个,它确实有效,但是 onStatusUpdated 方法没有参数。我如何找出实际点击了哪个按钮(三个正在使用的按钮)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多