으로 할 열심히하지 않아야을 손. Album.getInfo 메서드에 대한 last.fm API 사양은 매우 간단하며 REST API임을 사용하면 훨씬 간단 해집니다. 그냥 서버에서 XML 응답을 가져 와서 구문 분석하고 이미지의 URL을 얻으십시오. 나는이 코드를 오래 전에 썼지 만 여전히 작동해야합니다 :
String request = "http://ws.audioscrobbler.com/2.0/?method=" + method +
"&api_key="+apiKey;
request += "&artist=" + artist.replaceAll(" ", "%20");
if (method.equals("album.getinfo")) request += "&album=" + album.replaceAll(" ", "%20");
URL url = new URL(request);
InputStream is = url.openStream();
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(is);
NodeList nl = doc.getElementsByTagName("image");
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
if (n.getAttributes().item(0).getNodeValue().equals(imageSize)) {
Node fc = n.getFirstChild();
if (fc == null) return null;
String imgUrl = fc.getNodeValue();
if (imgUrl.trim().length() == 0) return null;
return new ImageIcon(new URL(imgUrl));
}
}
'apiKey' 란 무엇입니까? – Codevalley
http://www.last.fm/api/account의 last.fm에서 가져 오는 api 키입니다. 당신은 하나의 테스트를 b25b959554ed76058ac220b7b2e0a026 사용할 수 있지만 자신의 것을 얻으십시오. –