FileDocCategorySizeDatePackage
LevelMeterPlayer.javaAPI DocExample6761Wed Nov 10 13:04:18 GMT 2004com.oreilly.qtjnotebook.ch07

LevelMeterPlayer

public class LevelMeterPlayer extends Frame

Fields Summary
int[]
EQ_LEVELS
static final Dimension
meterMinSize
LevelMeter
meter
AudioMediaHandler
audioMediaHandler
Constructors Summary
public LevelMeterPlayer()

        super ("Audio Level Meter");
        // prompt for audio file
        QTFile file = QTFile.standardGetFilePreview(
                          QTFile.kStandardQTFileTypes);
        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);
        // add level meter to GUI
        meter = new LevelMeter();
        add (meter, BorderLayout.SOUTH);
        // set up repainting timer
        Timer t = new Timer (50, new ActionListener() {
                public void actionPerformed (ActionEvent ae) {
                    meter.repaint();
                }
            });
        t.start();
    
Methods Summary
public static voidmain(java.lang.String[] args)


          
        try {
            QTSessionCheck.check();
            Frame f= new LevelMeterPlayer();
            f.pack();
            f.setVisible(true);
        } catch (QTException qte) {
            qte.printStackTrace();
        }