Search code examples
androidcastinggoogle-castchromecast

Discovery of Chromecast devices using Android MediaRouter APIs


Discovery of Chromecast devices using Android MediaRouter APIs is not working as expected with latest mediarouter support library (version 19) and google play services version 4.2.43.

I'm using Cast Hello Text sample app for this issue. It can be found here: https://github.com/googlecast/CastHelloText-android.

I have my chromecast device plugged into the TV and in the same network as the Android device (Sender).

  1. The app comes up and finds the Chromecast device. I override some of the relevant MediaRouter.Callback methods, so I see the onRouteAdded() being called.
  2. Later, I unplug the device from my TV. I expect to get a onRouteRemoved() event. But this never happens.
  3. The app still displays the cast icon. On selecting the device from the cast icon, the app attempts to connect to the device and fails. Now I get onRouteUnSelected() and onRouteRemoved() events and the cast icon disappears.
  4. On plugging back the device to my TV and once the device is displaying the home screen, I expect to get a onRouteAdded() event. I do not get this event even after waiting for a few minutes.

This was working as expected in mediarouter library version 17 and with the preview google cast SDK.

So has something changed in terms of when these events are fired? what is the right way to find out when a chromecast device is added and when it is removed? I plan on using a custom UI with MediaRouter APIs to display the cast icon and the device list.


Solution

  • There is a bug in the latest version of Android SDK/Play services that causes the behavior you are seeing. This will be fixed in the next release of SDK and Google Play services.