Downloading large file blocks UI

29 views
Skip to first unread message

Carlos Verdier

unread,
Mar 16, 2017, 1:26:26 PM3/16/17
to CodenameOne Discussions
Hi

I’m having some problems related to large file downloads blocking the UI on iOS. I’ve created a test case to illustrate the problem.

public void start() {
    if(current != null){
        current.show();
        return;
    }
    final String cache = FileSystemStorage.getInstance().getAppHomePath() + "Video.mp4";
    Form hi = new Form("Video Test", new BorderLayout());
    Tabs tab = new Tabs();
    Button btnDownload = new Button("Download");
    Button btnRemove = new Button("Remove");
    Container contButtons = new Container(new FlowLayout());
    contButtons.add(btnDownload).add(btnRemove);
    Container contVideo = new Container(new BorderLayout());
    Container contTabVideo = new Container(new BorderLayout());
    contTabVideo.add(BorderLayout.CENTER, contVideo)
        .add(BorderLayout.SOUTH, FlowLayout.encloseCenterMiddle(contButtons));
    tab.addTab("Video Tab", contTabVideo);
    tab.addTab("Test Tab", new Container());
    hi.add(BorderLayout.CENTER, tab);
    hi.show();
    Media[] mVideo = {null};
    btnDownload.addActionListener((evt) -> {
        contButtons.replace(btnDownload, new InfiniteProgress(), null);
        contButtons.revalidate();
        /** 
         * Large file download blocks UI on iOS
         */
        Util.downloadUrlToFileSystemInBackground(url, cache, (e) -> {
            contButtons.replace(contButtons.getComponentAt(0), btnDownload, null);
            try {
                mVideo[0] = MediaManager.createMedia(cache, true);
                MediaPlayer mp = new MediaPlayer(mVideo[0]);
                mp.setAutoplay(true);
                /** 
                 * Loop not working
                 */                    
                mp.setLoop(true);
                contVideo.add(BorderLayout.CENTER, mp);
                contVideo.revalidate();
            } catch(IOException io) {                    
            }
        });
    });
    btnRemove.addActionListener((evt) -> {
        if (FileSystemStorage.getInstance().exists(cache)) {
            FileSystemStorage.getInstance().delete(cache);
            if (mVideo[0] != null) {
                mVideo[0].cleanup();
                contVideo.removeComponent(contVideo.getComponentAt(0));
                contVideo.revalidate();
            }
            ToastBar.showMessage("Video removed", FontImage.MATERIAL_INFO);
        }
    });
}


In the code above, if you press the button to download a Video, you can see the UI is blocked until it starts playing. You can’t even switch tabs.

This is happening on a old iPad Mini 1.

Another problem related with the video is that setLoop is not working. I can workaround this issue but not the blocked UI.

Thanks

Shai Almog

unread,
Mar 17, 2017, 1:59:26 AM3/17/17
to CodenameOne Discussions
Hi,
if you do this on more powerful hardware does it work?
If you don't have the progress indicator is the UI responsive?

Carlos Verdier

unread,
Mar 17, 2017, 6:43:15 AM3/17/17
to CodenameOne Discussions
On Friday, March 17, 2017 at 6:59:26 AM UTC+1, Shai Almog wrote:
Hi,
if you do this on more powerful hardware does it work?

I don't have a more powerful device with iOS. I do have powerful Android devices and works fine.
 
If you don't have the progress indicator is the UI responsive?

The UI becomes irresponsive even without progress indicator, just the screen waiting for the file to download.

I know it's unrelated, but what about setLoop not working? Do you need a separate thread for that?

Shai Almog

unread,
Mar 18, 2017, 2:14:21 AM3/18/17
to CodenameOne Discussions
You can open an issue about setLoop, it's something we'll need to investigate.

It's possible that just the process of downloading is taking up too much CPU. Do you have a network listener in place?
Reply all
Reply to author
Forward
0 new messages