FileDocCategorySizeDatePackage
StreamingLineSound.javaAPI DocExample1837Mon Jan 09 11:02:00 GMT 2006None

StreamingLineSound

public class StreamingLineSound extends Object implements LineListener

Fields Summary
File
soundFile
JDialog
playingDialog
PCMFilePlayer
player
Constructors Summary
public StreamingLineSound(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, "Streaming Sound");
        playingDialog.pack();


        player = new PCMFilePlayer (soundFile);
        // player.line.addLineListener (this);
        player.getLine().addLineListener (this);
        player.start();

    
Methods Summary
public static voidmain(java.lang.String[] args)

        JFileChooser chooser = new JFileChooser();
        chooser.showOpenDialog(null);
        File f = chooser.getSelectedFile();
        try {
            StreamingLineSound s = new StreamingLineSound (f);
        } catch (Exception e) {
            e.printStackTrace();
        }
    
public voidupdate(javax.sound.sampled.LineEvent le)

        LineEvent.Type type = le.getType();
        if (type == LineEvent.Type.OPEN) {
            System.out.println ("OPEN");
        } else if (type == LineEvent.Type.CLOSE) {
            System.out.println ("CLOSE");
            System.exit (0);
        } else if (type == LineEvent.Type.START) {
            System.out.println ("START");
            playingDialog.setVisible(true);
        } else if (type == LineEvent.Type.STOP) {
            System.out.println ("STOP");
            playingDialog.setVisible(false);
            player.line.close();
        }