Search code examples
androidgoogle-castmediarouter

Extend MediaRouteButton behaviour


I'm building an app that can cast to both Chromecast and AppleTV devices. Discovery of these devices is working: ChromeCasts are discovered using the MediaRouter and AppleTVs are discovered using SSDP. At the moment, I have a regular button that displays an combined list of discovered devices, but I'd like to have it use the fancy cast button.

Is there an elegant way to extend the MediaRouteButton to display my own list of discovered devices or should I just be creating my own button from scratch with the cast drawables?

I know that the MediaRouteButton class can be extended, but I'm not sure how to apply my extended button to the button declared via xml. I feel like I'm missing something painfully obvious, but I haven't found it yet.


Solution

  • You should be able to do this by using MediaRouteProvider APIs. The Cast SDK adds a Cast Media Route Provider and you can build your own provider, for whatever type of devices that you are interested in (there is an android sample that exhibits this but I am not sure how up-to-date it has been kept). If you want to use CastSDK (v3) to handle connection and establishment of sessions to both types of devices (the ones discovered by the Cast SDK itself and the ones you discover through your own provider), you should then use the Cast SDK's SessionProvider. There are posts (such as this) that ask about extending Session and SessionProviders in Cast SDK v3.