Search code examples
google-castgoogle-cast-sdk

Android start casting to a device chosen from a custom Cast Dialog


I have setup a custom Cast Dialog and added it using:

castButton.setDialogFactory(new DialogFactory());

My custom dialog retrieves available cast devices using the below code and display them as a list

MediaRouter.getInstance(getContext()).getRoutes();

How can I start casting to a CastDevice chosen from the above list?


Solution

  • Solved using:

    MediaRouter.getInstance(context).selectRoute(route)

    To disconnect I did:

    MediaRouter.getInstance(context).unselect(MediaRouter.UNSELECT_REASON_DISCONNECTED)