Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disconnect from Cast when finishing Activity?

Here is what I'm doing:

  • Manually connecting to ChromeCast via Settings.
  • Launching my app which manages Presentation to show custom layout using the ChromeCast device I'm already connected to.
  • Finishing my app by manually closing it.
  • By this time, I can still see my device screen casting. Here is where I want to disconnect from casting programmatically so I cannot longer see the screen casting.

While doing the presentation I have access to the Display I'm casting to:

MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
    return route != null ? route.getPresentationDisplay() : null;

Any ideas on how to achive this functionality?

UPDATE:

For those who are interested on this, this is how I did it (Thanks to Ali Naddaf response):

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public void disconnect(){
    MediaRouter mMediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
    mMediaRouter.selectRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouter.getDefaultRoute());
}
like image 665
LarryMustaine Avatar asked Dec 05 '22 22:12

LarryMustaine


1 Answers

For the ones like me who came looking for the answer using v3 Cast SDK:

mSessionManager.endCurrentSession(true);
like image 75
Alqueraf Avatar answered Dec 27 '22 00:12

Alqueraf