Below the sample code to add the mediaRouter listeners to the mediaRouter:
MediaRouter.Callback _cb = new MediaRouter.Callback() {
@Override
public void onRouteSelected(MediaRouter mediaRouter, int i, MediaRouter.RouteInfo routeInfo) {
Log.d("MediaRouteEvent:", "");
Log.d("onRouteSelected:", String.valueOf(_displayManager.getDisplays().length));
}
@Override
public void onRouteUnselected(MediaRouter mediaRouter, int i, MediaRouter.RouteInfo routeInfo) {
Log.d("MediaRouteEvent:", "");
Log.d("onRouteUnselected:", String.valueOf(_displayManager.getDisplays().length));
WritableMap wm = Arguments.createMap();
wm.putInt("displayCount", _displayManager.getDisplays().length);
sendEvent("routeEvent", wm);
}
@Override
public void onRouteAdded(MediaRouter mediaRouter, MediaRouter.RouteInfo routeInfo) {
Log.d("MediaRouteEvent:", "");
Log.d("onRouteAdded:", String.valueOf(_displayManager.getDisplays().length));
}
@Override
public void onRouteRemoved(MediaRouter mediaRouter, MediaRouter.RouteInfo routeInfo) {
Log.d("MediaRouteEvent:", "");
Log.d("onRouteRemoved:", String.valueOf(_displayManager.getDisplays().length));
}
@Override
public void onRouteChanged(MediaRouter mediaRouter, MediaRouter.RouteInfo routeInfo) {
Log.d("MediaRouteEvent:", "");
Log.d("onRouteChanged:", String.valueOf(_displayManager.getDisplays().length));
WritableMap wm = Arguments.createMap();
wm.putInt("displayCount", _displayManager.getDisplays().length);
sendEvent("routeEvent", wm);
}
@Override
public void onRouteGrouped(MediaRouter mediaRouter, MediaRouter.RouteInfo routeInfo, MediaRouter.RouteGroup routeGroup, int i) {
Log.d("MediaRouteEvent:", "");
Log.d("onRouteGrouped:", String.valueOf(_displayManager.getDisplays().length));
}
@Override
public void onRouteUngrouped(MediaRouter mediaRouter, MediaRouter.RouteInfo routeInfo, MediaRouter.RouteGroup routeGroup) {
}
@Override
public void onRouteVolumeChanged(MediaRouter mediaRouter, MediaRouter.RouteInfo routeInfo) {
}
};
_mediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, _cb);
Cheers and Peace out!!!