MediaStore download stuck at 0%

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.

Hi,

GroundSdk API must be called from main thread (unless stated otherwise in the documentation). Callbacks are called on the main thread too.
Thus, the download(…) call should happen on the main thread (I can’t tell if it is the case from you snippet), and the observer callback will be called on the main thread.
As a consequence you cannot use a CompletableFuture as you are likely to block the thread where the callback should be called.

Regards,

Mathieu

2 Likes

Thank you Mathieu, i think this is likely the issue.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.