FileDocCategorySizeDatePackage
JMFSound.javaAPI DocExample1587Mon Jan 09 11:02:00 GMT 2006None

JMFSound

public class JMFSound extends Object implements ControllerListener

Fields Summary
File
soundFile
JDialog
playingDialog
Constructors Summary
public JMFSound(File f)

        soundFile = f;
        // prepare a dialog to display while playing
        JOptionPane pane = new JOptionPane ("Playing " + f.getName(),
                                            JOptionPane.PLAIN_MESSAGE);
        playingDialog = pane.createDialog (null, "JMF Sound");
        playingDialog.pack();

        // get a player
        MediaLocator mediaLocator =
            new MediaLocator(soundFile.toURL());
        Player player =
            Manager.createRealizedPlayer (mediaLocator);
        player.addControllerListener (this);
        player.start();
        playingDialog.setVisible(true);
    
Methods Summary
public voidcontrollerUpdate(javax.media.ControllerEvent e)

        System.out.println (e.getClass().getName());
        if (e instanceof EndOfMediaEvent) {
            playingDialog.setVisible(false);
            System.exit (0);
        }
    
public static voidmain(java.lang.String[] args)

        JFileChooser chooser = new JFileChooser();
        chooser.showOpenDialog(null);
        File f = chooser.getSelectedFile();
        try {
            JMFSound s = new JMFSound (f);
        } catch (Exception e) {
            e.printStackTrace();
        }