android-sdk
android-sdk copied to clipboard
ImagesApi not responding
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();
}