Google Cast按钮未在Android中显示

时间:2018-02-04 15:06:25

标签: android chromecast google-cast

尝试在我的项目中使用Google的强制转换SDK v3,即使我在我附近有投射接收器,也无法显示强制转换按钮

我已将Google强制转换按钮添加到我的项目布局中,如下所示:

<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" />

上面的按钮是 NOT 一个菜单按钮,所以我在onCreate中设置了按钮,如下所示:

CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mediaRouteButton);

我还创建了CastOptionsProvider并在我的AndroidManifest文件

中指出了它

根据Google演员文档:

  

在v3中,发现过程自动启动和停止   当应用程序到达前台并进入时的框架   背景,分别。 MediaRouteSelector和MediaRouter.Callback   不应该使用。

任何想法为什么谷歌演员按钮不会自动出现,因为按钮应该处理他自己的状态?

修改

我当前的解决方案/解决方法是:

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);
    }
}

2 个答案:

答案 0 :(得分:6)

显然这是演员SDK中的一个错误。

我已经为它开了一张票,Google演员团队设法重现它并接受了这个错误。

以下是指向reported bug的链接,以便您跟踪

答案 1 :(得分:5)

一种可能性是您的应用程序ID尚不存在。 GoogleCast按钮未显示是应用程序ID无效。 您可以测试默认ID:

CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID