android-sdk icon indicating copy to clipboard operation
android-sdk copied to clipboard

ImagesApi not responding

Open stefanoromanello opened this issue 3 years ago • 1 comments

The problem is that the callback is never called causing the CountDownLatch to wait indefinitely. I don't understand why the getImage() method does not return a callback (Log.d("sync", "done") is never called)

 java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(1);

                  Log.d("sync", "started");
                  // Get bitmap with official api mSpotifyAppRemote .getImagesApi()
                  try {

                    mSpotifyAppRemote.getImagesApi().getImage(playerState.track.imageUri, Image.Dimension.MEDIUM)
                        .setResultCallback(bitmap -> {
                          Log.d("sync", "done");

                          ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                          bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
                          byte[] byteArray = byteArrayOutputStream.toByteArray();
                          String encoded = android.util.Base64.encodeToString(byteArray, android.util.Base64.DEFAULT);

                          myList.put("imageBase64", encoded);

                          latch.countDown();
                        });

                    Log.d("sync", "waiting");
                    latch.await();
                  } catch (InterruptedException e) {

                    Log.d("sync", "error");
                    latch.countDown();
                  }

stefanoromanello avatar Feb 05 '21 10:02 stefanoromanello