Saturday, May 1, 2010

Testing QuickTime for Java

I am experimenting with various media supporting libraries for Java these days. Java Media Framework (JMF) in the previous post is one of them.
I also found this interesting library provided by QuickTime. But it works only with QuickTime player. Given below are the steps I followed and a sample code I tested.

The first step is to install QuickTime. In QuickTime you can find a the java library QuickTime for Java in the part QuickTime/QTSystem/QTJava.zip. This QTJava.zip contains all the libraries needed.
I imported this QTJava.zip to Eclipse and tried the following sample code provided in QuickTime for Java Wiki page (http://en.wikipedia.org/wiki/QuickTime_for_Java).

import java.io.File;
import java.awt.*;

import quicktime.*;
import quicktime.std.movies.Movie;
import quicktime.app.view.QTFactory;
import quicktime.io.*;
import sun.audio.AudioPlayer;

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();
}


}

This code creates a QTJ player and you have to give a *.mov file as input for this sample. There are many other file types supported by QT for Java.
The only constraint with this is that you must have a QuickTime player to run any application you've written by using QuickTime for java.

No comments:

Post a Comment