【问题标题】:Google Cast button not showing in AndroidAndroid 中未显示 Google Cast 按钮
【发布时间】:2023-03-09 19:20:01
【问题描述】:

尝试在我的项目中使用 Google 的 cast SDK v3 时,即使我附近有活动的投射接收器,投射按钮也无法出现

我已将 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" />

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

CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mediaRouteButton);

我还创建了CastOptionsProvider 并在我的AndroidManifest 文件中指向它

根据 Google cast 文档:

在 v3 中,发现过程通过以下方式自动启动和停止 当应用程序进入前台并转到 背景,分别。 MediaRouteSelector 和 MediaRouter.Callback 不应该使用。

任何想法为什么 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:visibility="visible"吗?
  • @DanielZolnai 该按钮应该管理它自己的可见性。从消失开始,如果有可用的接收器应用程序应该变得可见。
  • 发现不起作用的原因可能有很多。 CastVideos 示例应用会发现您的接收器吗?

标签: android chromecast google-cast


【解决方案1】:

所以显然这是 cast SDK 中的一个错误。

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

这是reported bug 的链接,您可以跟踪它

【讨论】:

    【解决方案2】:

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

    CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-23
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 2013-08-17
      • 2019-10-06
      相关资源
      最近更新 更多