0

I need help with getting information from spotify. How from this link : https://api.spotify.com/v1/search?q=Songs+of+Innocence&type=album Can I take url:

"height" : 64,
        "url" : "https://i.scdn.co/image/eb740cef5aa3d5e119baf868bdff2dbb5cc1a59b",
        "width" : 64

And assign url to variable s in my code below:

  public void getCover(String album) {

            String query = "https://api.spotify.com/v1/search?q="+ encodeField(album)+"=album";
            java.net.URL url = null;
            try {
                BufferedImage image = null;
                url = new java.net.URL(query);
            } catch (MalformedURLException e1) {            
                e1.printStackTrace();
            }
            InputStream is = null;
            try {
                is = url.openStream();
            } catch (IOException e) {
                e.printStackTrace();
            }

            // get the text from the stream as lines
            java.io.BufferedReader reader = null;
            try {
                reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            String s;
            try {
                s = reader.readLine()) // read link with image 64x64 resolution
            } catch (IOException e) {

                e.printStackTrace();
            }
            try {
                //URL url2 = new URL("https://i.scdn.co/image/eb740cef5aa3d5e119baf868bdff2dbb5cc1a59b");
                URL url2 = new URL(s);
                image = ImageIO.read(url2);
                ImageIcon icon = new ImageIcon(image);
                jLabel2.setIcon(icon);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373

0 Answers0