Is it possible to programmatically connect to a chromecast route?

后端 未结 1 827
旧时难觅i
旧时难觅i 2020-12-12 00:02

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.

My plan was to have a

相关标签:
1条回答
  • 2020-12-12 00:21

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

    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.

    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.

    0 讨论(0)
提交回复
热议问题