Code Example
The following example shows an AWT file-selection dialog, and attempts to load and play the media file selected by the user.
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; } }Much of the example is involved with the building of the AWT GUI. Only two lines touch JMF. Manager.createRealizedPlayer implicitly creates a DataSource from a URL representation of the file, creates a Player, and realizes it, meaning that all resources necessary for playback are allocated and initialized. The getVisualComponent asks the Player for an AWT Component suitable for use in a GUI. If a control component were desired, it would be obtained with getControlPanelComponent and added to the GUI separately. Note that the developer is not concerned with the format of the media - this code works equally well for any media format that JMF can import and read.
Read more about this topic: Java Media Framework
Famous quotes containing the word code:
“Hollywood keeps before its child audiences a string of glorified young heroes, everyone of whom is an unhesitating and violent Anarchist. His one answer to everything that annoys him or disparages his country or his parents or his young lady or his personal code of manly conduct is to give the offender a sock in the jaw.... My observation leads me to believe that it is not the virtuous people who are good at socking jaws.”
—George Bernard Shaw (18561950)
“... the self respect of individuals ought to make them demand of their leaders conformity with an agreed-upon code of ethics and moral conduct.”
—Mary Barnett Gilson (1877?)