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);
}
});
}