-
urlConnection.connect();
-
BufferedReader in = new BufferedReader(new InputStreamReader(
-
urlConnection.getInputStream()));
-
StringBuffer sb = new StringBuffer();
-
String temp;
-
while ((temp = in.readLine()) != null) {
-
sb.append(temp);
-
}
-
JSONObject jObject = new JSONObject(sb.toString());
-
int count = jObject.getInt(“count”);
-
int index = count == 0 ? 0 : new Random().nextInt() % count;
-
JSONArray jArray = jObject.getJSONArray(“result”);
-
JSONObject obj = jArray.getJSONObject(index);
-
return obj.getString(“lrc”);
-
} catch (MalformedURLException e) {
-
// TODO Auto-generated catch block
-
e.printStackTrace();
-
} catch (IOException e) {
-
// TODO Auto-generated catch block
-
e.printStackTrace();
-
} catch (JSONException e) {
-
// TODO Auto-generated catch block
-
e.printStackTrace();
-
}
-
return null;
-
}
-
// 歌手,歌曲名中的空格进行转码
-
public String Encode(String str) {
-
try {
-
return URLEncoder.encode(str.trim(), “utf-8”);
-
} catch (UnsupportedEncodingException e) {
-
// TODO Auto-generated catch block
-
e.printStackTrace();
-
}
-
return str;
-
}
-
// 歌词文件网络地址,歌词文件本地缓冲地址
-
public boolean wrtieContentFromUrl(String urlPath, String lrcPath) {
-
Log.i(TAG, “lrcURL” + urlPath);
-
try {
-
URL url = new URL(urlPath);
-
URLConnection urlConnection = url.openConnection();
-
urlConnection.connect();
android音乐播放器开发在线加载歌词,大厂架构师经验分享
最新推荐文章于 2024-07-21 17:03:23 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)