I am using the GroundSdk for Android and I trying to download media from the drone into the mobile device. I have success downloading the thumbnails(different method), but when I try to retrieve the actual media the getStatus will only report that it is RUNNING and the getTotalProgress only reports 0 once and is never called again.
The way i set up the code is that I have a CompletableFuture that waits until a future is set when getStatus returns COMPLETE or ERROR. Is the observer running in the same thread as the media store download call, and thus hanging? If so how would you go on to wait until either.
The code is something similar to:
CompletableFuture<GetMediaStatus> result_future = new CompletableFuture<>();
_media_store.download(media_item, MediaDestination.platformMediaStore(AlbumName), downloader -> {
if (downloader == null)
return;
switch (downloader.getStatus()) {
case ERROR:
l.onError(new Exception("Failed to get media"));
result_future.complete(GetMediaStatus.ERROR);
break;
case COMPLETE:
File file = downloader.getDownloadedFile();
if (file != null)
try {
l.onAvailable(new FileInputStream(file));
result_future.complete(GetMediaStatus.SUCCESS);
} catch (IllegalAccessException | FileNotFoundException e) {
l.onError(e);
result_future.complete(GetMediaStatus.ERROR);
}
else {
l.onError(new Exception("Unexpectedly failed to get media"));
result_future.complete(GetMediaStatus.ERROR);
}
break;
case RUNNING:
System.out.println(downloader.getTotalProgress());
break;
case FILE_PROCESSED:
break;
}
});
try {
result_future.get();
}
catch (ExecutionException | InterruptedException e) {
l.onError(e);
}
Let me know if more information is needed.