O'Reilly logo

QuickTime for Java: A Developer's Notebook by Chris Adamson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Compiling QTJ Code

Once you’ve installed QuickTime and QuickTime for Java, you have everything you need to start developing QTJ applications—no separate SDK is required.

How do I do that?

You can begin by compiling a trivial application to check the QuickTime and QTJ versions, as shown in Example 1-3.

Example 1-3. Checking the version of QuickTime

package com.oreilly.qtjnotebook.ch01;
import quicktime.QTSession;
import quicktime.util.QTBuild;
public class QTVersionCheck {
  public static void main (String[  ] args) {
      try {
          QTSession.open( );
          System.out.println ("QT version: " +
              QTSession.getMajorVersion( ) +
              "." +
              QTSession.getMinorVersion( ));
          System.out.println ("QTJ version: " +
              QTBuild.getVersion( ) +
              "." +
              QTBuild.getSubVersion( ));
          QTSession.close( );
      } catch (Exception e) {
          e.printStackTrace( );

The compilation is the tricky step here. If you do a straightforward javac, bad things happen:

cadamson% javac src/com/oreilly/qtjnotebook/ch01/QTVersionCheck.java
  package quicktime does not exist
import quicktime.QTSession;
  package quicktime.util does not exist
import quicktime.util.QTBuild;
  cannot resolve symbol
symbol  : variable QTSession 
location: class com.oreilly.qtjnotebook.ch01.QTVersionCheck
          QTSession.open( );

Instead, you have to explicitly provide the path to QTJava.zip, which contains the QTJ classes. On the Mac OS X command line, you would do this as follows:


Here, as in many examples, you should type the entire command on one line. It’s broken up in the text for printing purposes.

cadamson% javac -classpath /System/Library/Java/Extensions/QTJava.zip 

On Windows, the path to QTJava.zip would point to wherever the QuickTime installer put the file, which presumably means into your Java installation’s lib/ext:

C:\qtjtests\book stuff\code>javac -classpath
  "c:\Program Files\Java\j2re1.4.2\lib\ext\QTJava.zip"

Once the code compiles, running it is a lot easier—you don’t need to explicitly put QTJava.zip in the runtime classpath to run a QTJ application. Just supply the class name to run, as the following output illustrates:


Using the ant buildfile provided with the downloaded book code (and described in the Preface) makes compiling a lot easier!

cadamson% java -cp classes com.oreilly.qtjnotebook.ch01.QTVersionCheck
QT version: 6.5
QTJ version: 6.1

What just happened?

As for what this trivial first application actually does, a read-through of the main( ) method shows it doing four things:

  1. Opening the QuickTime session

  2. Printing the QuickTime version by making calls to quicktime.QTSession

  3. Printing the QuickTime for Java version by making calls to quicktime.util.QTBuild

  4. Closing the QuickTime session

If any of these throws an exception, it’s caught and printed to standard-out.

What about...

...the mismatch between the version numbers? QuickTime and QuickTime for Java versions are somewhat independent, because not every QT update merits a QTJ update. Typically, you’ll see both roll out a major version at the same time, but then a number of QuickTime updates will be issued, usually bug-fix updates or minor feature releases, without any changes to QTJ.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required