Skip to content

Instantly share code, notes, and snippets.

@codenameone
Created February 13, 2016 20:20
Show Gist options
  • Save codenameone/fb73f5d47443052f8956 to your computer and use it in GitHub Desktop.
Save codenameone/fb73f5d47443052f8956 to your computer and use it in GitHub Desktop.
Demo of the MediaPlayer class from Codename One
final Form hi = new Form("MediaPlayer", new BorderLayout());
hi.setToolbar(new Toolbar());
Style s = UIManager.getInstance().getComponentStyle("Title");
FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_VIDEO_LIBRARY, s);
hi.getToolbar().addCommandToRightBar(new Command("", icon) {
@Override
public void actionPerformed(ActionEvent evt) {
Display.getInstance().openGallery((e) -> {
if(e != null && e.getSource() != null) {
String file = (String)e.getSource();
try {
Media video = MediaManager.createMedia(file, true);
hi.removeAll();
hi.add(BorderLayout.CENTER, new MediaPlayer(video));
hi.revalidate();
} catch(IOException err) {
Log.e(err);
}
}
}, Display.GALLERY_VIDEO);
}
});
hi.show();
@codenameone
Copy link
Author

Demonstrates the MediaPlayer, MediaManager usage as well as the openGallery API.

From the Codename One project

@jegesh
Copy link

jegesh commented Jan 7, 2018

How about an example of playing a video from a remote url?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment