2
votes

hey i have been trying to use the Util.downloadUrlToFileSystemInBackground method but its not working.when i run the codename One simulator it gets stuck in a loop.what i would like is the download to work in the background ,plus i would also like to display a download progress.below is the code responsible for the download

    Map<String, String> data = myList.get(i);
               String link = data.get("fileurl");
                Util.downloadUrlToFileSystemInBackground(link,title,   new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        try{
                            InputStream is = Storage.getInstance().createInputStream(link);
                            Media mm = MediaManager.createMedia(is, "audio/mp3");
                            mm.play();
                        }
                        catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    }
                });
1

1 Answers

0
votes

You download the URL to a file named title then in the callback after the download completed you try to open a Storage file (which is not a file system file).

I'm guessing title isn't a valid file either...

This shouldn't get into a loop but it won't work. One obvious fix is to replace downloadUrlToFileSystemInBackground with downloadUrlToStorageInBackground.

Notice that Storage != FileSystemStorage.