尝试在我的项目中使用 Google 的 Cast SDK v3,即使我附近有激活的 Cast 接收器,Cast 按钮也没有出现
我已将 Google Cast 按钮添加到我的项目布局中,如下所示:
<android.support.v7.app.MediaRouteButton
android:id="@+id/media_route_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:mediaRouteTypes="user"
android:visibility="gone" />
上面的按钮不是菜单按钮,所以我在 onCreate 中设置了按钮,如下所示:
CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mediaRouteButton);
我还创建了 CastOptionsProvider
并在我的 AndroidManifest
文件中指向它
根据 Google cast 文档:
In v3, the discovery process is started and stopped automatically by the framework when the app comes to the foreground and goes to the background, respectively. MediaRouteSelector and MediaRouter.Callback should not be used.
知道为什么 google cast 按钮没有自动出现,因为该按钮应该处理他自己的状态吗?
编辑
我当前的解决方案/解决方法是:
castContext.addCastStateListener(
newState -> updateCastButtonVisibility(button, newState)
);
private static void updateCastButtonVisibility(View button, int state) {
if (state == CastState.NO_DEVICES_AVAILABLE) {
button.setVisibility(View.GONE);
} else {
button.setVisibility(View.VISIBLE);
}
}
最佳答案
关于android - Google Cast 按钮未在 Android 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48609497/