我应该使用什么标志进行Chromecast发现?

时间:2014-03-11 08:15:07

标签: android google-cast chromecast

我有一个控制UPnP MediaRenderers的Android应用程序,现在我想修改它以使用Chromecasts。

由于我必须混合使用UPnP和Chromecast,而我的应用程序没有使用ActionBarCompat,因此我无法使用Cast Companion Library,因此我尝试自行集成Cast SDK,构建自定义按钮。

对于设备发现,我正在使用MediaRouter.addCallback,但我真的不知道是否应该指定一个标志。根据Javadoc的说法,第三个参数是:

Flags to control the behavior of the callback. May be zero or a combination of CALLBACK_FLAG_PERFORM_ACTIVE_SCAN and CALLBACK_FLAG_UNFILTERED_EVENTS.

但是国旗的文件说:

public static final int CALLBACK_FLAG_PERFORM_ACTIVE_SCAN

Flag for addCallback(MediaRouteSelector, MediaRouter.Callback): Actively scan for routes while this callback is registered.

When this flag is specified, the media router will actively scan for new routes. Certain routes, such as wifi display routes, may not be discoverable except when actively scanning. This flag is typically used when the route picker dialog has been opened by the user to ensure that the route information is up to date.

Active scanning may consume a significant amount of power and may have intrusive effects on wireless connectivity. **Therefore it is important that active scanning only be requested when it is actually needed to satisfy a user request to discover and select a new route**.

但是根据Cast UX指南,我不应该在ActionBar中显示Cast按钮,除非我知道网络中有设备。所以我不能等待用户请求使用主动扫描,因为如果应用程序没有发现设备,那么用户就没有按钮可以触摸并请求路由!

这是我的疑惑:

- 我应该在显示电池电量耗尽之前使用CALLBACK_FLAG_PERFORM_ACTIVE_SCAN但是确保按钮在必要时显示?这是标准应用程序的功能吗?

- 即使有可用的Chromecast,我是否应该使用该标志并冒险显示该按钮?

- 我应该使用CALLBACK_FLAG_REQUEST_DISCOVERY吗?有什么区别吗?

谢谢!

2 个答案:

答案 0 :(得分:3)

您可以使用CALLBACK_FLAG_PERFORM_ACTIVE_SCAN标记并在开始活动时注册回调。然后框架将每30秒左右继续重新扫描一次(我不记得确切的数字)。该过程经过高度优化,因此您不必过多担心电池消耗。当您离开应用程序时,可以删除回调。

编辑:由于演员阵容的扩展和镜像的引入等,现在建议使用更保守的旗帜CALLBACK_FLAG_REQUEST_DISCOVERY

答案 1 :(得分:0)

MediaRouter的文档说CALLBACK_FLAG_PERFORM_ACTIVE_SCAN"可能消耗大量电力"最近Ali Naddaf转而使用Cast Companion Library中的CALLBACK_FLAG_REQUEST_DISCOVERY,所以我建议你改用它。