7

I previously developed an android sender app with the preview SDK and found that when a Chromecast was turned on or off, the app very quickly discovered this and changed the state of the media route button.

However with the new SDK, if a Chromecast is unplugged while the app isn't connected to it, MediaRouter.Callback.onRouteUnselected() is never called and the Cast icon remains visible. In some cases even if the app is closed and opened again, onRouteAdded is called on startup with the details of the previously connected Chromecast, even though it's not plugged in anymore and hence not on the network, which suggests that there's some kind of cache somewhere.

I'm noticing this both with my own app (which uses the companion library) and the example CastVideos-android app on github. This sets up the callback like so:

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 results in a pretty rough user experience - is there any way I can improve it? Perhaps some flag that I can pass that'll perform an even more active scan than CALLBACK_FLAG_PERFORM_ACTIVE_SCAN, hence detecting Chromecasts that are no longer on the network? Or perhaps some method that I can hit at intervals to scan again and make sure the chromecast is still there? I've had a look through the API but I can't see anything.

EDIT: Worse still, I've also noticed that if a Chromecast is unplugged then you attempt to cast to it, it will disconnect (good) but won't detect the Chromecast when it's plugged back in. This is true even if you get out of the app and start it up again.

Alex Gilleran
  • 597
  • 3
  • 12
  • Are you expecting a lot of users to unplug their own Chromecast, then purposefully attempt to cast to it, then not know why it isn't working? – ianhanniballake Mar 03 '14 at 02:11
  • It's not inconceivable for someone to bump the cord out then try to start the cast before they switch to the Chromecast's channel on the TV. The other problem is that it makes live demos where you want to both demonstrate the chromecast app and actually unplug the thing and pass it around really nerve-wracking. – Alex Gilleran Mar 03 '14 at 02:18
  • Moreover, if I accidentally bumped the cord out of my chromecast and couldn't see the picture but could still see the cast button on the sender app, I'd assume the chromecast was still turned on but there was something wrong with the HDMI connection. Eventually I'd figure it out, but it's not great. – Alex Gilleran Mar 03 '14 at 02:27

1 Answers1

5

The behavior you have outlined is caused by a bug in the SDK that is going to be addressed in the next release of the Google Play services.

Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28
  • Is there a similar bug meaning when disconnecting via the Sender app, the Receiver is not closed, despite running the "teardown" code? I experience this quite a bit. – Mr Pablo Jan 21 '15 at 16:36
  • What is the "tearDown" code? If you are referring to a specific code, you need to be clear on what it is. In addition, you need to be specific about the receiver that is used as well. Your question is a totally different one from the original post here so you need to create a new post rather than asking a different question in comments. – Ali Naddaf Jan 21 '15 at 16:57
  • teardown() is a function in the sample Google Cast Android apps. – Mr Pablo Jan 22 '15 at 13:14