androidgoogle-castgoogle-cast-sdk

How to stop casting immediately on Android?


I need to stop casting after the user enabled it inside my app. The app listened to MediaRouter.Callback as below:

 private val mediaRouterCallback = object : MediaRouter.Callback() {
    override fun onRouteChanged(router: MediaRouter?, route: RouteInfo?) {
        super.onRouteChanged(router, route)
       
        // notify observers that casting occurs
    }
}

Now, in the observers, I need to stop casting immediately when the user should not use casting inside the app.

Let's suppose the code below is inside a Fragment and observes the casting event, so what would be the implementation code for stopCasting() method, for example:

when (event) {
    PreventCasting -> {
         stopCasting()
    }
}

Solution

  • If you want to stop casting you only need to use castContext?.sessionManager?.endCurrentSession(true)