Trying to use Google, running the SDK v3 in my project, the broadcast button will not appear even if I have active receivers.
I added the Google cast button to my project layout like this:
<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 set the button in my onCreate like this:
CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mediaRouteButton);
I also created CastOptionsProviderand pointed to it in the fileAndroidManifest
According to Google cast docs
In v3, the discovery process starts and stops automatically when the application comes to the fore and goes to accordingly. MediaRouteSelector and MediaRouter.Callback should not be used.
Any ideas why the google google button does not appear automatically since the button should handle its own state?
EDIT
/ :
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);
}
}