Google Cast Chromecast SDK 消息格式错误(没有级别值)

Google Cast Chromecast SDK Message is malformed (No value for level)

我知道这个帖子与这个帖子重复,但没有人回答。

Receving weird Json Error from custom Chromecast recevier app

我正在尝试从 Android 应用程序投射到 chromecast。我遵循了 Google.

中的以下示例

https://developers.google.com/cast/docs/android_sender_integrate

https://developers.google.com/cast/docs/caf_receiver_basic

我可以成功连接到 chromecast,它会在电视上显示我的自定义 html 和应用名称。

当我发送视频时出现错误,它说 JSON 没有音量值。它显示图像、名称和描述的元数据,但不播放它

public void playOnChromecast() {

    CastSession session =CastContext.getSharedInstance(this).getSessionManager().getCurrentCastSession();

    if(session == null) return;

    MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    movieMetadata.putString(MediaMetadata.KEY_TITLE, this.video.getName());
    movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, this.video.getDescription());
    movieMetadata.addImage(new WebImage(Uri.parse(this.video.getThumbnail())));
    movieMetadata.addImage(new WebImage(Uri.parse(this.video.getThumbnail())));

    MediaLoadOptions.Builder mediaLoadOptionsBuilder = new MediaLoadOptions.Builder();
    mediaLoadOptionsBuilder.setAutoplay(true);
    mediaLoadOptionsBuilder.setPlayPosition(0);

    MediaTrack track = new MediaTrack.Builder(this.video.getId(), MediaTrack.TYPE_VIDEO)
            .setName(this.video.getName())
            .setSubtype(MediaTrack.SUBTYPE_NONE)
            .setContentId(String.valueOf(this.video.getId()))
            .setLanguage("es").build();

    ArrayList<MediaTrack> tracks = new ArrayList<MediaTrack>();
    tracks.add(track);

    JSONObject jsonObj = null;try {
        jsonObj = new JSONObject();
        jsonObj.put("description", this.video.getDescription());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    MediaInfo mediaInfo = new MediaInfo.Builder("http://clips.vorwaerts-gmbh.de/VfE_html5.mp4")
            .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setContentType("video/mp4")
            .setMetadata(movieMetadata)
            .setMediaTracks(tracks)
            .setCustomData(jsonObj)
            .build();

    RemoteMediaClient remoteMediaClient = session.getRemoteMediaClient();
    remoteMediaClient.load(mediaInfo, mediaLoadOptionsBuilder.build());
}

这样做的结果就是什么都没有。在控制台中,我收到以下消息。

W/MediaControlChannel: Message is malformed (No value for level); ignoring: (JSON)

是 (JSON) SDK 发送到设备的一堆 JSON 数据。

{"type":"MEDIA_STATUS","status":[{"mediaSessionId":1,"playbackRate":1,"playerState":"IDLE","supportedMediaCommands":15,"volume":{},"media":{"contentId":"http://clips.vorwaerts-gmbh.de/VfE_html5.mp4","streamType":"BUFFERED","contentType":"video/mp4","metadata":{"metadataType":1,"images":[{"url":"http://cachepicapica.gomovil.co/videos-transcoded/fd42e6b6-b1f8-4eee-87c9-9b024ea41f0b/thumbnail.jpg","width":0,"height":0},{"url":"http://cachepicapica.gomovil.co/videos-transcoded/fd42e6b6-b1f8-4eee-87c9-9b024ea41f0b/thumbnail.jpg","width":0,"height":0}],"title":"Susanita","subtitle":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit"},"tracks":[{"trackId":3,"type":"VIDEO","trackContentId":"3","name":"Susanita","language":"es"}],"customData":{"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit"}},"currentItemId":1,"extendedStatus":{"playerState":"LOADING","media":{"contentId":"http://clips.vorwaerts-gmbh.de/VfE_html5.mp4","streamType":"BUFFERED","contentType":"video/mp4","metadata":{"metadataType":1,"images":[{"url":"http://cachepicapica.gomovil.co/videos-transcoded/fd42e6b6-b1f8-4eee-87c9-9b024ea41f0b/thumbnail.jpg","width":0,"height":0},{"url":"http://cachepicapica.gomovil.co/videos-transcoded/fd42e6b6-b1f8-4eee-87c9-9b024ea41f0b/thumbnail.jpg","width":0,"height":0}],"title":"Susanita","subtitle":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit"},"tracks":[{"trackId":3,"type":"VIDEO","trackContentId":"3","name":"Susanita","language":"es"}],"customData":{"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit"}}},"repeatMode":"REPEAT_OFF"}],"requestId":0}

我在 JSON 中看到音量字段是空的,它应该有电平字段和静音字段。我想那是错误,但我不知道如何修复它,因为 json 是从 Google SDK 构建的。

有什么想法吗?

谢谢!

更新:尝试使用 Styled 接收器,它只适用于 MP4 文件,但不适用于 HLS 流。在两次尝试中都没有出现上面显示的错误。

已解决,我缺少此处所述的跨源资源Headers

https://developers.google.com/cast/docs/player

我还注意到,如果我使用自定义接收器,它会不断抛出上述错误(消息格式错误)。

我改用了默认样式的接收器。

如果GoogleCast SDK开发者添加错误信息就好了