9

Trying to use Google's cast SDK v3 in my project, the cast button is failing to appear even though I have cast receivers active near me

I have added the Google cast button to my project layout like so:

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

The button above is NOT a menu button, so I have setup the button in my onCreate like so:

CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mediaRouteButton);

I have also create the CastOptionsProvider and pointed to it in my AndroidManifest file

According to the Google cast docs:

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.

Any ideas why is the google cast button not appearing automatically since the button should handle his own state?

EDIT

My current solution/workaround is:

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);
    }
}
TareK Khoury
  • 12,721
  • 16
  • 55
  • 78

2 Answers2

5

One possibility is that your application id does not exist yet. The GoogleCast button doesn't show up is the application id is invalid. You can test out the default id:

CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
PhoenixB
  • 398
  • 1
  • 3
  • 12
5

So apparently this is a bug in the cast SDK.

I have opened a ticket for it and the Google cast team managed to reproduce it and accepted this bug.

Here is a link to the reported bug so you can track it

TareK Khoury
  • 12,721
  • 16
  • 55
  • 78