【发布时间】:2020-02-03 08:17:56
【问题描述】:
我想在片段中使用 CastStateListener 来检查投射设备是否可用。 Fragment中使用的代码是
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mCastContext = CastContext.getSharedInstance(mContext)
mCastStateListener = CastStateListener { newState ->
if (newState != CastState.NO_DEVICES_AVAILABLE) {
castDevicesAvailable = true
}
}
}
override fun onResume() {
super.onResume()
mCastContext?.addCastStateListener(mCastStateListener)
}
override fun onPause() {
super.onPause()
mCastContext?.removeCastStateListener(mCastStateListener)
}
此代码在 Fragment 中使用时不会在 CastListner 中给我回调,但当我在 Activity 或 Fragment 中使用它时它可以正常工作。
我正在使用自定义视图
<androidx.mediarouter.app.MediaRouteButton
android:id="@+id/media_route_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:actionButtonStyle="@android:style/Widget.Holo.Light.MediaRouteButton"/>
我想根据可用的投射设备隐藏/显示视图
【问题讨论】:
标签: android video-streaming google-cast exoplayer2.x google-cast-sdk