我知道这条线是这条线的复制品,但没有答案。
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流无效。在两次尝试中,均未出现上述错误。