How to get custom data from receiver

限于喜欢 提交于 2019-12-24 21:22:01

问题


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.

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
            ....
        }
    });

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


回答1:


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.



来源:https://stackoverflow.com/questions/22210712/how-to-get-custom-data-from-receiver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!