问题
I'm trying to get a list of cast devices programmatically in Android, without using the MediaRouteActionProvider button in the SDK.
I create a MediaRouter and MediaRouteSelector like so:
mMediaRouter = MediaRouter.getInstance(this);
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent.CATEGORY_CAST)
.build();
I then start discovery:
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
In the onProviderAdded callback method, I only seem to get 3 providers: Android, com.google.android.youtube, and com.google.android.gms. Only 'android' provides a route, which is named 'Phone'.
Why isn't my chromecast device showing up? Other apps can see it, so I should have connectivity.
回答1:
Ok, what worked for me was this:
Add the onRouteAdded method on your Media Router Callback and look for devices with the description: "Chromecast"
回答2:
You must listen for onRouteAdded and for onRouteRemoved for updates. Inside this methods you can ask MediaRouter for all available routes and filter only those with:
playbackType == MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE
来源:https://stackoverflow.com/questions/21774479/cant-get-a-list-of-cast-devices-on-the-network