Chromecast Sender App Doesn't Detect Disconnection/Reconnection

你说的曾经没有我的故事 提交于 2019-12-21 10:46:24

问题


I previously developed an android sender app with the preview SDK and found that when a Chromecast was turned on or off, the app very quickly discovered this and changed the state of the media route button.

However with the new SDK, if a Chromecast is unplugged while the app isn't connected to it, MediaRouter.Callback.onRouteUnselected() is never called and the Cast icon remains visible. In some cases even if the app is closed and opened again, onRouteAdded is called on startup with the details of the previously connected Chromecast, even though it's not plugged in anymore and hence not on the network, which suggests that there's some kind of cache somewhere.

I'm noticing this both with my own app (which uses the companion library) and the example CastVideos-android app on github. This sets up the callback like so:

mMediaRouter = MediaRouter.getInstance(context);
mMediaRouteSelector = new MediaRouteSelector.Builder().addControlCategory(
    CastMediaControlIntent.categoryForCast(mApplicationId)).build();

mMediaRouterCallback = new CastMediaRouterCallback(this, context);
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
    MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);

This results in a pretty rough user experience - is there any way I can improve it? Perhaps some flag that I can pass that'll perform an even more active scan than CALLBACK_FLAG_PERFORM_ACTIVE_SCAN, hence detecting Chromecasts that are no longer on the network? Or perhaps some method that I can hit at intervals to scan again and make sure the chromecast is still there? I've had a look through the API but I can't see anything.

EDIT: Worse still, I've also noticed that if a Chromecast is unplugged then you attempt to cast to it, it will disconnect (good) but won't detect the Chromecast when it's plugged back in. This is true even if you get out of the app and start it up again.


回答1:


The behavior you have outlined is caused by a bug in the SDK that is going to be addressed in the next release of the Google Play services.



来源:https://stackoverflow.com/questions/22137467/chromecast-sender-app-doesnt-detect-disconnection-reconnection

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