Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get list of all cast devices using cast SDK?

I am struggling to get list of all chrome cast devices available in my network, I am able to make it work with there default implementation of adding a media router button in the action bar. What I want to achieve is to get list of all cast devices available including Fire stick and smart TV (basically all the devices which supports DIAL protocol).

My list will contain all chrome cast devices and all DIAL protocol supported devices. I am using cast 3 SDK provided in android.

like image 332
Pranav Agrawal Avatar asked Nov 01 '25 05:11

Pranav Agrawal


1 Answers

    MediaRouter router = 
    MediaRouter.getInstance(a context);
    List<MediaRouter.RouteInfo> routes = router.getRoutes();

    List<CastDevice> devices = new ArrayList<>();

    for (MediaRouter.RouteInfo routeInfo : routes) {
        CastDevice device = CastDevice.getFromBundle(routeInfo.getExtras());
        if (device != null) {
            devices.add(device);
        }
    }
like image 51
stephane k. Avatar answered Nov 02 '25 18:11

stephane k.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!