从 Android 控制第三方 Cast 会话?

Control third-party Cast session from Android?

我想观察和控制由另一个应用启动的 Chromecast 会话。

但是,当使用 MediaRouter 连接时,我无法在不中断的情况下加入正在进行的会话。一旦我 select 一条路线,我的应用程序就会替换之前的路线。

如何使用 Android SDK 监控 Chromecast 会话(并能够播放、暂停、查看进度等),而无需替换当前正在播放的接收器应用程序?

第一个选项:

您可以使用 RemotePlaybackClient

Controlling a remote playback route

When you select a remote playback route your app acts as a remote control. The device at the other end of the route handles all content data retrieval, decoding, and playback functions. The controls in your app's UI communicate with the receiver device using a RemotePlaybackClient object.

Javadoc:

RemotePlaybackClient

A helper class for playing media on remote routes using the remote playback protocol defined by MediaControlIntent.

The client maintains session state and offers a simplified interface for issuing remote playback media control intents to a single route.

您可以使用 RemotePlaybackClient(Context context, MediaRouter.RouteInfo route)

创建它

您可以通过调用route.supportsControlCategory

检查MediaRouter.Route是否支持远程请求

第二个选项:

如果您的应用不支持此功能,您可以尝试通过 CastSession. This way you app will communicate with the other app through the chromeecast. With CastSession.getRemoteMediaClient() you get a RemoteMediaClient.

进行管理