Volley无法在某些设备上连接到服务器

时间:2018-07-01 16:14:26

标签: android android-volley

我有一个应用程序,使用排球连接到服务器以获取一些在线歌曲并以JSON格式下载数据。我已将此应用程序部署到Playstore。但是我的许多用户抱怨在线歌曲没有显示。每次为这些用户调用OnErrorResponse方法。我已经在我的设备和朋友的手机上对其进行了测试。一切正常。可能是什么问题?

PS:我没有使用任何重试策略或自定义标头。

代码:

  private void getNewSongs() {

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, newSongsUrl, null, new Response.Listener<JSONObject>() {
        @SuppressLint("LongLogTag")
        @Override
        public void onResponse(JSONObject response) {

            JSONObject artistObject = null;
            String artist = "";
            String albumID = "";
            String artistID = null;

            try {


                JSONObject songListObjects = response.getJSONObject("new_song");

                    if(songListObjects.has("data")){

                        JSONObject data = songListObjects.getJSONObject("data");

                        if(data.has("song_list")) {

                            JSONArray songList = data.getJSONArray("song_list");

                            for (int i=0;i<5;i++){

                                JSONObject songListObject = songList.getJSONObject(i);

                                if (songListObject.has("mid")) {

                                    Log.e("SongListObject has", "songmid");
                                    String songID = songListObject.getString("mid");
                                    String songTitle = songListObject.getString("name");
                                    long duration = songListObject.getLong("interval") * 1000;
                                    Log.e("Title:", songTitle);
                                    Log.e("Duration:", String.valueOf(duration));

                                    JSONObject albumObject  = songListObject.getJSONObject("album");

                                    if(albumObject.has("mid")){

                                        albumID = albumObject.getString("mid");


                                    }



                                    JSONArray artistArray = songListObject.getJSONArray("singer");

                                    for (int j = 0; j < artistArray.length(); j++) {

                                        artistObject = artistArray.getJSONObject(j);

                                        if (j == 0) {

                                            if (artistObject.has("name")) {


                                                Log.e("ArtistObject: ", "has name");

                                                artist = artistObject.getString("name");
                                                artistID = artistObject.getString("mid");

                                            }
                                        } else {

                                            if (artistObject.has("name")) {

                                                Log.e("ArtistObject: ", "has name");

                                                artist = artist + " ft. " + artistObject.getString("name");

                                            }
                                        }
                                    }

                                    String songData = "http://xx.x.x.xx.com/xxxx" + songID + ".xx?;
                                    //   String songData = "http://xx.x.xx.xx.com/xxxx"+songID+".xxx?;
                                    String albumArtURL = "https://y.xx.xx/x/xx/x" + alx+bumID + ".jpg";
                                    SongInfoModel songInfoModel = new SongInfoModel(123, songTitle,artistID, ((artist == null || (artist.length() == 0)) ? "Unknown" : artist), duration, songData, albumArtURL);
                                    SoundCloudNewSongs.add(songInfoModel);

                                    if (getView() != null){

                                        getView().findViewById(R.id.onlineProgressLoad).setVisibility(View.GONE);
                                        getView().findViewById(R.id.mainLayout).setVisibility(View.VISIBLE);

                                    }



                                }

                            }


                        }
                    }



                newSongsAdapter = new NewSongsAdapter(SoundCloudNewSongs, getContext(),listenerOnline,1);
                recyclerView_newSongs.setAdapter(newSongsAdapter);


            } catch (JSONException e) {


            }

        }
    }, new Response.ErrorListener() {
        @SuppressLint("LongLogTag")
        @Override
        public void onErrorResponse(VolleyError error) {




        }
    });

    songQueue.add(jsonObjectRequest);

}

0 个答案:

没有答案