How can I get list of all cast devices using cast

2019-08-21 17:27发布

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.

1条回答
\"骚年 ilove
2楼-- · 2019-08-21 18:07
    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);
        }
    }
查看更多
登录 后发表回答