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);
}
}
The Cast button is in the overflow area.If you have multiple extensions on your browser, the Cast button may be shown in the button overflow area. Expand the extension button area by clicking the Chrome Settings menu. in the upper-right hand corner of your browser to see if you can locate the Cast button there.
Scroll down to the Devices section and look for your Chromecast. If your Chromecast is listed, it is on the same network as your Android. If your Chromecast isn't listed, it may be connected to a different network than your Android. Visit the Google support website for help switching networks.
Chromecast icon doesn't appear Is this the case? Make sure the source device is on the same Wi-Fi network as the Chromecast, or vice versa of course. It can help to quickly change the Chromecast's Wi-Fi settings, or you can check the settings on your smartphone, tablet or PC.
Mirror your Android phone or tablet screen to the TV See exactly what's on your Android device by casting your screen to the TV. From your Android phone or tablet, open the Google Home app. Tap the left hand navigation to open the menu. Tap Cast screen / audio and select your TV.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With