MediaRouter: Detecting a chromecast device when using ActionBarSherlock?

依然范特西╮ 提交于 2019-12-13 18:38:16

问题


So I modified the Mediarouter source to be dependent on ActionBarSherlock rather than AppCompat. However, now the callback from MediaRouteAdapter onDeviceAvailable(...) is not being called.

Any ideas on how to get this to work?

I don't want to leave the cast button always visible. Rather, I want to use onDeviceAvailable(..) to only make it visible when a device is available.


回答1:


I found a hack on how to fix this.

If you use appcompat, the cast icon will only be visible when you have a chromecast device in your network, based upon your implementation of onDeviceAvailable(...).

However, if you use ABS, the onDeviceAvailable(...) method is not called when a chromecast device is available on the network. So in order to see the cast icon, we must set it as always visible.

So the issue is that the cast icon is always visible (when you set visibility to visible or when you add it to your actionbar).

HOWEVER: The MediaRouter has different view states. One for when a cast device is available and one for when there isn't one available.

The Mediarouter library consists of drawable pngs that are the icons for when a device is available or not.

Just replace the one for which 'no route is available' with a blank resource, or anything that suits the app.

When a device is available, the correct cast icon will show, and when not available your custom resource will show (blank if the resource is a blank view).

Here are full details on how to obtain the mediarouter source code, and how to fix this: http://www.droidorbit.com/2013/10/mediarouter-and-actionbarsherlock.html



来源:https://stackoverflow.com/questions/19519980/mediarouter-detecting-a-chromecast-device-when-using-actionbarsherlock

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