Darussian
Darussian

Reputation: 1593

How to get custom data from receiver

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.

Upvotes: 0

Views: 940

Answers (1)

Ali Naddaf
Ali Naddaf

Reputation: 19044

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.

Upvotes: 2

Related Questions