使用OKHTTP獲取網路歌詞出現障礙。請大神幫忙解決一下。
public String get(String url) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url(url)
.method("GET", null)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
public void getLyricFromGet() {
new Thread() {
@Override
public void run() {
super.run();
try {
String Str=songList.get(i).song;
String Str1=songList.get(i).singer;
String[] str=Str.split("[.]");
str[0].trim();
// curl 'http://gecimi.com/api/lyric/海闊天空/Beyond'
String result = get("http://gecimi.com/api/lyric/"+str[0]);
System.out.println(str[0]);
Log.e("TAG", result);
Message msg = Message.obtain();
msg.what = GET;
msg.obj = result;
handler.sendMessage(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
只能獲取一首歌的歌詞。當我點擊其他的或者上下曲的時候就會出現{"code":0,"count":0,"result":[]}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/32190.html
標籤:Android
上一篇:有小程式可視化開發工具嗎?
