代码之家  ›  专栏  ›  技术社区  ›  agusvazquez

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

  •  1
  • agusvazquez  · 技术社区  · 6 年前

    我知道这条线是这条线的复制品,但没有答案。

    Receving weird Json Error from custom Chromecast recevier app

    我正在尝试从Android应用程序转换为chromecast。我遵循了以下来自谷歌的例子。

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

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

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

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

    结果什么都没有。在控制台中,我得到以下消息。

    带MediaControlChannel:消息格式错误(级别没有值); 忽略:(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中看到volume字段为空,应该有level字段和mute字段。我想这就是错误所在,但我不知道如何修复它,因为json是从Google SDK构建的。

    有什么想法吗?

    非常感谢。

    更新:尝试改用样式化的接收器,它只对MP4文件有效,但对HLS流无效。在两次尝试中,均未出现上述错误。

    1 回复  |  直到 6 年前
        1
  •  0
  •   agusvazquez    6 年前

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

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

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

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

    如果Google Cast SDK开发人员添加一条错误消息就好了。