This example shows how to build a simple media player in Java.
This program load and play selected audio or video media file using Java Media Framework (JMF) library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import javax.media.*; import java.io.File; import java.awt.*; public class TrivialJMFPlayer extends Frame { public static void main (String[] args) { try { Frame f = new TrivialJMFPlayer(); f.pack(); f.setVisible (true); } catch (Exception e) { e.printStackTrace(); } } public TrivialJMFPlayer() throws java.io.IOException, java.net.MalformedURLException, javax.media.MediaException { FileDialog fd = new FileDialog (this, "TrivialJMFPlayer", FileDialog.LOAD); fd.setVisible(true); File f = new File(fd.getDirectory(), fd.getFile()); Player p = Manager.createRealizedPlayer (f.toURI().toURL()); Component c = p.getVisualComponent(); add(c); p.start(); } } |