【问题标题】:How to send the JSONArray to Receiver app from the sender app for chromecast in android如何从发送方应用程序将 JSONArray 发送到接收方应用程序以在 android 中进行 chromecast
【发布时间】:2014-08-18 12:15:12
【问题描述】:

无法使用 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"
  },
]

【问题讨论】:

    标签: android json chromecast


    【解决方案1】:

    这里有一个想法: 使用 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());
        }
    

    【讨论】:

    • 感谢您的回复,但设置 customData() 方法只接受参数为 jsonObject。有什么方法可以传递 MediaInfo.Builder 类中的 jsonArray 值
    • 正如@Saeid 建议的那样,创建一个JSONObject,整个字段是一个jsonobj。在他的示例中,jsonArrayWrapper 是一个 JSONObject,因此您应该能够使用它。
    • 如何在receiver app中访问这个customData?
    猜你喜欢
    • 2017-09-08
    • 2013-09-03
    • 1970-01-01
    • 2019-03-24
    • 1970-01-01
    • 1970-01-01
    • 2017-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多