Can't get a list of cast devices on the network

大城市里の小女人 提交于 2019-12-07 09:53:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!