无法使用MediaInfo.Builder类从发件人应用程序向接收者应用程序发送JSONArray值。我已经使用了setCustomData(JSONObject obj),我们只能发送JSONObject,但是如果可能的话我需要使用setCustomData()方法将JSONArray发送到接收器应用程序,否则如果有其他默认方法或任何想法将JSONArray值发送到chromecast接收器应用程序请告诉我。
先谢谢。
我尝试过使用JSONObject:
MediaMetadata mediaMetadata = new MediaMetadata(
MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, ""
+ singers.getText().toString());
mediaMetadata.putString(mediaMetadata.KEY_ALBUM_TITLE, ""
+ songTitle.getText().toString());
MediaInfo mediaInfo = new MediaInfo.Builder(songUrl)
.setContentType("audio/mp3")
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
// here set the customData {"music":"Illayaraja","album_id":"T0000266","duration":"04:57",....}
.setCustomData(customJsonObj)
.setMetadata(mediaMetadata).build();
mRemoteMediaPlayer
.load(mApiClient, mediaInfo, true)
.setResultCallback(
new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
@Override
public void onResult(MediaChannelResult result) {
if (result.getStatus().isSuccess()) {
Log.d(Tag, "Media loaded Successfully"
+ result.getStatus());
} else {
Log.d(Tag,
"Media loaded Not Successfully"
+ result.getStatus());
}
}
});
但我需要将JSONArray值传递给接收器应用程序,就像这样
"customData": [
{
"songid": 236854,
"songtitle": "Kadal Anukkal",
"cdimg": "http://cdn.raaga.com/r_img/250/t/t0002491.jpg",
"lyricist": "Vairamuthu",
"lang": "T",
"singers": "Vijay Prakash, Shreya Ghoshal",
"album": "Enthiran",
"album_id": "T0002491",
"music": "AR. Rahman",
"duration": "05:46"
},
]
答案 0 :(得分:0)
这是一个想法: 使用JSonObject来包装你的JSonArray。 这是一个例子:
try {
JSONObject myJsonObject;
myJsonObject.put("field1", "value1");
JSONArray myJSonArray = new JSONArray();
myJSonArray.put(myJsonObject);
JSONObject jsonArrayWrapper = new JSONObject();
jsonArrayWrapper.put("MyArray", myJSonArray);
} catch (JSONException e) {
Log.d("Tag", e.getMessage());
}