本文介绍了如何从接收器获取自定义数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我试图将Chromecast集成到我们的应用中,并且在加入已运行的应用时遇到了接收方数据问题。

I'm attempting to integrate Chromecast into our app and I'm running into an issue with getting data from the receiver when joining an already running application.

当首先启动应用程序,我使用RemoteMediaPlayer设置元日期使用

When first launching the application i set meta date with the RemoteMediaPlayer using

 public class CastMessageStream extends RemoteMediaPlayer {
    public void setMetadata(GoogleApiClient apiClient, CastingObject castingObject, String seriesId, String description, String episodeNumber, String title) {
        JSONObject payload = _initJsonObject(COMMAND_KEY_SET_METADATA);
        try {
            payload.put(KEY_SUB_TITLE, castingObject.castingSubUrl);
            payload.put(KEY_TITLE, title);
            payload.put(KEY_SERIES_ID, seriesId);
            payload.put(KEY_EPISODE_NUMBER, episodeNumber);
            payload.put(KEY_DESCRIPTION, description);
            payload.put(KEY_VIDEO_HEADER, castingObject.description);
           sendMessage(apiClient, payload.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

/**
 * Send messages to the reciever using the NAMESPACE
 */
private final void sendMessage(GoogleApiClient apiClient, String message)
        throws IOException, IllegalArgumentException, IllegalStateException {
    Cast.CastApi.sendMessage(apiClient, NAMESPACE, message);
}

加入已运行的应用程序的代码

Code for joining the already running application

 Cast.CastApi.launchApplication(googleApiClient, APP_ID).setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>() {
        @Override
        public void onResult(Cast.ApplicationConnectionResult applicationConnectionResult) {
            mMessageStream = new CastMessageStream();
            MediaInfo mediaInfo =  mMessageStream.getMediaInfo();
            MediaStatus mediaStatus = mMessageStream.getMediaStatus();
            JSONObject jsonObject = mediaInfo.getCustomData(); // Returns null
            MediaMetadata metadata = mediaInfo.getMetadata(); // Returns null
            ....
        }
    });

如何从接收器获取自定义信息。我有它在iOS上工作,所以我知道它可能。

How do I get custom information from the receiver. I have it working on iOS so i know its possible.

推荐答案

在我看来,你正在扩展 RemoteMediaPlayer 并覆盖它的 sendMessage()。实际上不建议您考虑您的任务;如果您想要使用媒体发送其他数据,则需要使用各种调用和对象中可用的 customData 字段。例如, MediaInfo 对象可以包含 customData ,您可以在其中添加这些附加字段,因此可以使用多个控制命令如 load(),play(),pause(),....如果您选择覆盖RemoteMediaPlayer的 sendMessage()那么你还需要在接收端处理附加功能。

It seems to me that you are extending the functionality of the RemoteMediaPlayer and overriding its sendMessage(). That is actually not recommended for the task that you have in mind; if you want to send additional data with your media, you need to use, for example, the customData field that is available in various calls and objects . For example, MediaInfo object can have customData and you can add these additional fields there, so can a number of control commands like load(), play(), pause(), .... If you choose to override the RemoteMediaPlayer's sendMessage() then you need to handle the additional functionality on the receiver side as well.

这篇关于如何从接收器获取自定义数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:47