Android Chromecast Companion Library - set TextTrackStyle error 2103

779 Views Asked by At

I'm using CastCompanionLibrary-Android and I'm trying to set custom TextTrackStyle for the captions.

I'm setting this TexTextStyle to the MediaInfo while I'm creating it:

                // set CC style
                TextTrackStyle textTrackStyle = new TextTrackStyle();
                textTrackStyle.setBackgroundColor(Color.parseColor("#FFFFFF"));
                textTrackStyle.setForegroundColor(ContextCompat.getColor(mContext, R.color.blue));

                MediaInfo mediaInfo = new MediaInfo.Builder(url)
                        .setStreamDuration(movieVideoItem.getDuration())
                        .setStreamType(MediaInfo.STREAM_TYPE_NONE)
                        .setContentType(type)
                        .setMetadata(mediaMetadata)
                        .setMediaTracks(tracks)
                        .setCustomData(customData)
                        .setTextTrackStyle(textTrackStyle)
                        .build();

But there is no visible result on the Chromecast side. I also tried to change VideoCastManager method setTextTrackStyle:

 public void setTextTrackStyle(TextTrackStyle style) {
    // CUSTOM TEXT TRACK STYLE HERE
    TextTrackStyle textTrackStyle = new TextTrackStyle();
    textTrackStyle.setBackgroundColor(Color.parseColor("#FF0000"));
    textTrackStyle.setForegroundColor(Color.parseColor("#0000FF"));

    mRemoteMediaPlayer.setTextTrackStyle(mApiClient, textTrackStyle)
            .setResultCallback(new ResultCallback<MediaChannelResult>() {
                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.ccl_failed_to_set_track_style,
                                result.getStatus().getStatusCode());
                    }
                }
            });
    for (VideoCastConsumer consumer : mVideoConsumers) {
        try {
            consumer.onTextTrackStyleChanged(textTrackStyle);
        } catch (Exception e) {
            LOGE(TAG, "onTextTrackStyleChanged(): Failed to inform " + consumer, e);
        }
    }
}

But in this ResultCallback I'm getting error code 2103 which I found here: developers google

public static final int REPLACED
Status code indicating that the request's progress is no longer being tracked because another request of the same type has been made before the first request completed.

Constant Value: 2103

I don't know what this error code means, or what I'm doing wrong. The Chromecast implementation should be able to handle custom TextTrackStyle (at least for embedded VTT type)

MediaManager.onMetadataLoaded = function (event) {
    .......
    console.log("### RESOLVED TEXT TRACK TYPE " + textTrackType);
    if (textTrackType ==
        sampleplayer.TextTrackType.SIDE_LOADED_TTML &&
        event.message && event.message.activeTrackIds && event.message.media &&
        event.message.media.tracks) {
        _processTtmlCues(
            event.message.activeTrackIds, event.message.media.tracks);
    } else if (!textTrackType || textTrackType == sampleplayer.TextTrackType.SIDE_LOADED_UNSUPPORTED) {
        // If we do not have a textTrackType, check if the tracks are embedded
        _maybeLoadEmbeddedTracksMetadata(event);
    }
    MediaManager['onMetadataLoadedOrig'](event);
}


 function _maybeLoadEmbeddedTracksMetadata(info) {
    if (!info.message || !info.message.media) {
        return;
    }
    var tracksInfo = _readInBandTracksInfo();
    if (tracksInfo) {
        textTrackType = sampleplayer.TextTrackType.EMBEDDED;
        tracksInfo.textTrackStyle = info.message.media.textTrackStyle;
        MediaManager.loadTracksInfo(tracksInfo);
    }
}

The result on the Chromecast is just white text with black background.

// EDIT Chromecast receiver log added:

There is Chromecast receiver log where I found some TextTrackStyle but this is not my style that I'm trying to set:

 Received message: {"data":"{\"requestId\":4,\"type\":\"EDIT_TRACKS_INFO\",\"textTrackStyle\":{\"fontScale\":1,\"foregroundColor\":\"#4285F4FF\",\"backgroundColor\":\"#FFFFFFFF\"},\"mediaSessionId\":1}"

Those are different colors that I'm actually sending from my Android Sender app. I cannot see any TextTrackStyle inside the onLoad method at all. So I'm not sure if the problem is on Android side or on Chromecast side?

1

There are 1 best solutions below

0
On

Just Make Sure to add your setTextTrackStyle function inside mediaclient.load call back if the the statue of the result isSuccess.