是否有可能以编程方式连接到Chromecast路由? [英] Is it possible to programmatically connect to a chromecast route?

查看:137
本文介绍了是否有可能以编程方式连接到Chromecast路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个chromecast接收器应用程序,它将(希望)允许我远程将警报消息放在电视机上作为提醒。

I'm writing a chromecast receiver application that will (hopefully) allow me to remotely put alert messages up on my TV to serve as reminders.

我的计划是在我的家庭网络上有一个专用的无线设备,它将不断地轮询来自中央服务器的新消息。当找到新消息时,它会连接到Chromecast路由,打开电视并显示新消息。

My plan was to have a dedicated wireless device on my home network that would constantly poll for new messages from a centralized server. When a new message was found, it would connect to a chromecast route, turning on the TV and displaying the new message.

但据我所知,唯一的激活Chromecast路线的方法是手动点击我的Chrome浏览器或无线设备上的Chromecast图标。

But as far as I can tell, the only way to activate a chromecast route is by manually clicking the chromecast icon on my Chrome browser or wireless device.

有没有一种方法可以通过编程方式激活Chromecast?是否可以在发件人完成?

Is there a way, programmatically, to activate the chromecast? Can it be done in the sender?

推荐答案

您可以编程扫描投射设备并根据需要连接到它们。步骤如下:

You can programmatically scan for cast devices and connect to them if needed. Steps are:


  1. 从系统获取MediaRouter单例实例: mMediaRouter
  2. 构建一个选择器:
    mMediaRouteSelector = new MediaRouteSelector.Builder()
    .addControlCategory(
    CastMediaControlIntent

    mMediaRouter.addCallback(mMediaRouteSelector());}}。build();
  3. 添加回调以启动扫描:

    MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);

  4. onRouteAdded()和<$当您发现或移除路由时,您的回调(即 mMediaRouterCallback )的c $ c> onRouteRemoved()将被调用。您可以在应用中维护路由列表,并使用这两个回调使它们保持最新。

  5. 您可以通过调用 mMediaRouter.selectRoute( aRouteInfo)。然后调用回调函数的 onRouteSelected(),您可以像平常一样提取投射设备并按需要进行操作。

  1. Get an instance of the MediaRouter singleton from the system: mMediaRouter
  2. Build a selector: mMediaRouteSelector = new MediaRouteSelector.Builder() .addControlCategory( CastMediaControlIntent .categoryForCast(YOUR_APP_ID)).build();
  3. Add a callback to initiate scan: mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
  4. The onRouteAdded() and onRouteRemoved() of your callback (i.e. mMediaRouterCallback) will be called as routes are discovered or removed. You can maintain a list of routes in your app and keep them up to date by using these two callbacks.
  5. You can select a route by calling mMediaRouter.selectRoute(aRouteInfo). Then the onRouteSelected() of your callback will be called and you can extract the cast device as usual and do as you please.

请注意,如果您想在电视上向用户显示通知,那么您的应用程序应该在当时在Chromecast上运行你想发送通知。

These said, remember that if you want to show a notification to users on TV your app should be running on the chromecast at the time you want to send the notification.

这篇关于是否有可能以编程方式连接到Chromecast路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆