FileDocCategorySizeDatePackage
BasicAudioControlsPlayer.javaAPI DocExample4324Wed Nov 10 12:38:30 GMT 2004com.oreilly.qtjnotebook.ch07

BasicAudioControlsPlayer

public class BasicAudioControlsPlayer extends Frame implements ChangeListener

Fields Summary
JSlider
balanceSlider
JSlider
trebleSlider
JSlider
bassSlider
AudioMediaHandler
audioMediaHandler
Constructors Summary
public BasicAudioControlsPlayer()

        super ("Basic Audio Controls");
        // prompt for audio file
        QTFile file = QTFile.standardGetFilePreview(null);
        OpenMovieFile omf = OpenMovieFile.asRead (file);
        Movie movie = Movie.fromFile (omf);
        MovieController controller = new MovieController (movie);
        // get AudioMediaHandler for first audio track
        for (int i=1; i<=movie.getTrackCount(); i++) {
            Track t = movie.getTrack(i);
            Media m = t.getMedia();
            MediaHandler mh = m.getHandler();
            if (mh instanceof AudioMediaHandler) {
                audioMediaHandler = (AudioMediaHandler) mh;
                break;
            }
        }
        if (audioMediaHandler == null) {
            System.out.println ("No audio track");
            System.exit(-1);
        }
        // add controller to GUI
        setLayout (new BorderLayout());
        Component comp =
            QTFactory.makeQTComponent(controller).asComponent();
        add (comp, BorderLayout.NORTH);
        // build balance, treble, bass controls in a panel
        Panel controls = new Panel(new GridLayout (3,2));
        controls.add (new JLabel ("Balance"));
        balanceSlider = new JSlider (-1000, 1000, 0);
        balanceSlider.addChangeListener (this);
        controls.add (balanceSlider);
        controls.add (new JLabel ("Treble"));
        trebleSlider = new JSlider (-256, 256, 0);
        trebleSlider.addChangeListener (this);
        controls.add (trebleSlider);
        controls.add (new JLabel ("Bass"));
        bassSlider = new JSlider (-256, 256, 0);
        bassSlider.addChangeListener (this);
        controls.add (bassSlider);
        add (controls, BorderLayout.SOUTH);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        try {
            QTSessionCheck.check();
            Frame f= new BasicAudioControlsPlayer();
            f.pack();
            f.setVisible(true);
        } catch (QTException qte) {
            qte.printStackTrace();
        }
    
public voidstateChanged(javax.swing.event.ChangeEvent ev)

        Object source = ev.getSource();
        try {
            if (source == balanceSlider) {
                // balance
                float newBal =
                    (float) (balanceSlider.getValue() / 1000f);
                audioMediaHandler.setBalance (newBal);
            } else {
                // bass & treble
                audioMediaHandler.setSoundBassAndTreble (
                                      bassSlider.getValue(),
                                      trebleSlider.getValue());
            }


        } catch (QTException qte) {
            qte.printStackTrace();
        }