gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:01:56 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com