如果正在直播,如何更改MiniController按钮

时间:2019-06-04 17:24:02

标签: android casting chromecast

将实时内容投射到chromecast时,我需要显示一个播放/停止切换按钮,而不是播放/暂停按钮,但是在投射其他视频时,我们仍然需要播放/暂停按钮。

我将微控制器的投射按钮设置为自定义按钮,在onResume中,我调用了函数,该函数根据投射的对象绑定不同的可绘制对象。问题是,当我将视频更改为在已经显示了微控制器的页面上进行实时直播(或其他方式)时,它不会再次调用onResume(正确地如此),并且保持相同的按钮。我不知道微控制器内是否有其他事件可以使用。我尝试使用SessionManagerListener和UiController将函数绑定到某些事件,但是它们都存在问题(我可能做错了一些,不知道)。

我的功能是:

fun checkButton() {
    activity?.let {
        val mCastContext = CastContext.getSharedInstance(activity!!.baseContext)
        val mCastSession = mCastContext.sessionManager.currentCastSession

        if (mCastSession?.remoteMediaClient?.currentItem != null) {
            val drawablePlay = ContextCompat.getDrawable(it, R.drawable.cast_ic_mini_controller_play)
            val drawableStop = ContextCompat.getDrawable(it, R.drawable.cast_ic_mini_controller_stop)

            uiMediaController.bindImageViewToPlayPauseToggle(button, drawablePlay!!, drawableStop!!, drawableStop, ProgressBar(it), false)
        }
    }
}

我希望每次miniController加载或类似的东西时都调用我的函数。

谢谢!

1 个答案:

答案 0 :(得分:0)

找到它...看起来uiMediaController.bindImageViewToPlayPauseToggle已经自动执行此操作,它已经具有在实时流式传输时使用停止按钮的逻辑...