Quick Time For Java - Code Example

Code Example

The following example shows an AWT file-selection dialog and then tries to import and play the selected media file.

import java.io.File; import java.awt.*; import quicktime.*; import quicktime.std.movies.Movie; import quicktime.app.view.QTFactory; import quicktime.io.*; public class TrivialQTJPlayer extends Frame { public static void main (String args) { try { QTSession.open; Frame f = new TrivialQTJPlayer; f.pack; f.setVisible (true); } catch (Exception e) { e.printStackTrace; } } public TrivialQTJPlayer throws QTException { FileDialog fd = new FileDialog (this, "TrivialJMFPlayer", FileDialog.LOAD); fd.setVisible(true); File f = new File (fd.getDirectory, fd.getFile); OpenMovieFile omf = OpenMovieFile.asRead (new QTFile (f)); Movie m = Movie.fromFile (omf); Component c = QTFactory.makeQTComponent(m).asComponent; add (c); m.start; } }

Most of the code in this example involves itself with setting up the GUI. The only calls to QTJ are the calls to OpenMovieFile.asRead and Movie.fromFile, which create a QuickTime movie from the specified file, and the calls to create an AWT component from the QTFactory. This example puts the movie into the frame and immediately starts playing it; if a control bar (aka a "scrubber") were desired, you would create a MovieController from the Movie and then create a component from the controller, rather than from the movie.

Read more about this topic:  Quick Time For Java

Famous quotes containing the word code:

    Wise Draco comes, deep in the midnight roll
    Of black artillery; he comes, though late;
    In code corroborating Calvin’s creed
    And cynic tyrannies of honest kings;
    He comes, nor parlies; and the Town, redeemed,
    Gives thanks devout; nor, being thankful, heeds
    The grimy slur on the Republic’s faith implied,
    Which holds that Man is naturally good,
    And—more—is Nature’s Roman, never to be
    scourged.
    Herman Melville (1819–1891)

    Many people will say to working mothers, in effect, “I don’t think you can have it all.” The phrase for “have it all” is code for “have your cake and eat it too.” What these people really mean is that achievement in the workplace has always come at a price—usually a significant personal price; conversely, women who stayed home with their children were seen as having sacrificed a great deal of their own ambition for their families.
    Anne C. Weisberg (20th century)