Reputation: 144
Clicking on the "stop casting" button in the default dialog used by MediaRouteButton
triggers the callbacks for SessionManagerListener::onSessionEnded
and dismisses the Chromecast notification controls. However the video keeps playing on the TV.
I'm also using the com.google.android.exoplayer2.ext.cast.CastPlayer
to start the Chromecast. The SessionAvailabilityListener::onCastSessionUnavailable
callback is triggered as well.
This problem doesn't happen when using the close button of the Chromecast notification.
Upvotes: 0
Views: 570
Reputation: 144
What happens when you click on the "stop casting" button is that this method MediaRouter::unselect
is called. What you need to do is listen to when that happens and end the current session manually.
Here's an example:
MediaRouter.getInstance(context).addCallback(
MediaRouteSelector
.Builder()
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
.build(),
object: MediaRouter.Callback() {
override fun onRouteUnselected(
router: MediaRouter?,
route: MediaRouter.RouteInfo?,
reason: Int
) {
if(reason in listOf(MediaRouter.UNSELECT_REASON_STOPPED, MediaRouter.UNSELECT_REASON_DISCONNECTED)) {
CastContext.getSharedInstance(context).sessionManager.endCurrentSession(true)
}
}
}
)
Upvotes: 1