0

我正在使用CastCompanionLibrary-Android并且正在尝试TextTrackStyle为字幕设置自定义。

TexTextStyle在创建它时将其设置为 MediaInfo:

                // 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();

但是在 Chromecast 端没有可见的结果。我也尝试改变VideoCastManager方法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);
        }
    }
}

但在这ResultCallback我得到了code 2103我在这里发现的错误:开发人员谷歌

public static final int REPLACED
状态码指示不再跟踪请求的进度,因为在第一个请求完成之前已经发出了相同类型的另一个请求。

常数值:2103

我不知道这个错误代码是什么意思,或者我做错了什么。Chromecast 实现应该能够处理自定义TextTrackStyle(至少对于嵌入式VTT类型)

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

Chromecast 上的结果只是带有黑色背景的白色文本。

// 编辑 Chromecast 接收器日志添加:

有 Chromecast 接收器日志,我在其中找到了一些TextTrackStyle,但这不是我想要设置的样式:

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

这些是我实际从我的 Android Sender 应用程序发送的不同颜色。我根本看不到方法TextTrackStyle内部的任何内容onLoad。所以我不确定问题出在 Android 端还是 Chromecast 端?

4

0 回答 0