Earlier, I developed an Android sender application with a preview SDK and found that when I turned on or off Chromecast, the application very quickly detected this and changed the state of the media route button.
However, with the new SDK, if Chromecast is disabled while the application is not connected to it, MediaRouter.Callback.onRouteUnselected () is never called, and the Cast icon remains visible. In some cases, even if the application is closed and opened again, onRouteAdded is called when it starts with information about a previously connected Chromecast, although it is no longer connected and, therefore, is not connected to the network, which suggests that there is some kind of cache somewhere.
I notice this with both my own application (which uses a companion library) and the CastVideos-android sample application on github. This sets up the callback as follows:
mMediaRouter = MediaRouter.getInstance(context); mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory( CastMediaControlIntent.categoryForCast(mApplicationId)).build(); mMediaRouterCallback = new CastMediaRouterCallback(this, context); mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
This leads to a rather rude user - is there any way to improve it? Perhaps some kind of flag that I can pass will perform an even more active scan than CALLBACK_FLAG_PERFORM_ACTIVE_SCAN, therefore, detecting Chromecast that are no longer online? Or maybe some method that I can repeat at intervals to check again and make sure that the chromometer still exists? I looked at the API but can't see anything.
EDIT: Worse, I also noticed that if Chromecast is disabled, then you try to drop it, it will disconnect (good), but will not detect Chromecast when it reconnects. This is true even if you exit the application and run it again.
android chromecast google-cast
Alex gilleran
source share