android - Google Cast 按钮未在 Android 中显示

标签 android chromecast google-cast

尝试在我的项目中使用 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);
    }
}

最佳答案

很明显这是 cast SDK 中的错误。

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

这是 reported bug 的链接所以你可以追踪它

关于android - Google Cast 按钮未在 Android 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48609497/

相关文章:

ssl - Chromecast 上的 Html5 音频 - SSL

java - Android 6 上的 setMyLocationEnabled() 错误

java - RequestBody 参数很多时如何传递内容?

chromecast - Chrome Cast 发送器 "session_error"NOT_FOUND

javascript - Chromecast崩溃

android - 添加媒体路由器转换按钮时出错

android - 更改 tabHost 上的文本大小

android - 在 SQLiteDatabase.query() 中使用 String[] selectionArgs

android - 将 Google Home 响应转换到电视上的 Chromecast

google-cast - 带有谷歌 Chromecast 的 RTMP