我正在从事音乐流媒体服务项目。我首先在启动应用程序时显示缩略图夹克图像。 我已经获取了所有String Json结果,并且我已经使用Gson lib将Jason结果转换为hashmap。 我想要做的是将基本网址与地图值相结合并返回?或传递结果,以便我可以将结果与另一个线程一起使用以显示缩略图图像。请给我一些答案.. :(
MainActivity.java
private static final String baseURLforgetNewMusic = "https://s3-ap-northeast-1.amazonaws.com/goblinsbucket/Artists/";
....
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
new Connection().execute(getMusicInfo_URL + "getNewMusic.php");
// Connect to the server.
}
private class Connection extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
return getMusicInfo(urls[0]);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
}
....
private String getMusicInfo(String url) {
InputStream inputStream = null;
String inputStr = "";
HashMap<String, Object> map = new HashMap<String, Object>();
try {
URL getMusicUrl = new URL(url);
conn = (HttpURLConnection) getMusicUrl.openConnection();
conn.setDoInput(true);
conn.connect();
Log.d(TAGCP, "MADE POST REQUEST TO THE GIVEN URL");
inputStream = conn.getInputStream();
if (inputStream != null) {
inputStr = Util.convertInputStreamToString(inputStream);
Log.i(TAGCS, inputStr);
Music list = new Gson().fromJson(inputStr, Music.class);
for (Music.MusicInfo info : list.musicInfo) {
System.out.println(baseURLforgetNewMusic + info.artists
+ "/" + info.file_name);
}
} else {
inputStr = "Did not work!";
Log.d(TAGRR, inputStr);
}
} catch (Exception e) {
Log.i("InputStream", e.getLocalizedMessage());
}
return inputStr;
}
Results: (I want to use these url to show thumbnail images on the main view.)
I/System.out(22054): https://s3-ap-northeast-1.amazonaws.com/goblinsbucket/Artists/BrunoMars/Grenade
I/System.out(22054): https://s3-ap-northeast-1.amazonaws.com/goblinsbucket/Artists/BrunoMars/Justthewayyouare
I/System.out(22054): https://s3-ap-northeast-1.amazonaws.com/goblinsbucket/Artists/Beenzino/Aquaman
I/System.out(22054): https://s3-ap-northeast-1.amazonaws.com/goblinsbucket/Artists/Gummy/Thinkaboutme
答案 0 :(得分:0)
尝试使用此库显示图像:
https://github.com/nostra13/Android-Universal-Image-Loader
您可以在此处传递网址列表,并在网格视图中显示图片。
如果你想像CoverFlow那样制作酷炫的专辑封面,请使用:
答案 1 :(得分:0)
尝试使用截击来加载图像。它比Universal Image Loader更快更容易使用。该库包含一个名为NetworkImageView的类,它将为您加载所有图像。