The QTFactory class provides ``factory'' methods for creating classes used to present media that QuickTime can import. The makeDrawable() methods of QTFactory use the QuickTime importers to return an appropriate QuickTime object that can present any of a wide range of media types (images, movies, sounds, MIDI, and so on) that QuickTime can import.
Given a file, a Java InputStream object, or a URL, the makeDrawable() methods that belong to the QTFactory class examine the contained media and return an object that best presents that kind of media. For example:
Once you have the QTDrawable object, you merely add it to the canvas and the visual component of the media is presented in the canvas' display space.
There are three versions of the makeDrawable() method. The first two methods deal with a file, either local or remote:
The QTFile version is a local file, whereas the URL version can use any of the protocols known to QuickTime:
In this method, the media data can be derived from any source -- for example, from a ZipEntry, from a local or remote file, or from memory.
The readBytes() method of the input stream is used to read all of the source object's bytes into memory. Then this memory is used to create the appropriate QTDrawable.
In the first two cases, QuickTime can use details about the file to determine the type of media that the file contains. Many media formats are not self-describing. That is, they don't have information in the data that describes what they are. Usually, the file type describes to QuickTime this important detail.
In the case of the InputStream, however, because the data can come from an unknown or arbitrary source, your application must describe to QuickTime the format of the source data so that it can import it successfully. As such, these methods require the provision of a hintString and hintType. You can specify that the hint is either the file extension, Mac OS file type, or MIMEType of the source data.
Once the makeDrawable() methods determine the media, they create either a Movie or a GraphicsImporter as the QuickTime object to present that media. They then pass off this Movie or GraphicsImporter to a QTDrawableMaker to return a QTDrawable object to present that Movie or GraphicsImporter.
Your application uses the default QTDrawableMaker if you do not specify one. This returns a QTPlayer that creates a MovieController for the Movie or a GraphicsImporteDrawer for the GraphicsImporter. An application can also specify a custom QTDrawableMaker that will create a required object for one or both of these two cases.
The QTFactory also provides methods to locate files in the known directories of the Java application when it executes. In order for QuickTime to open a local file, it must have the absolute path and name of the file. Your application may want to open files where it can know the relative location of the file from where it is executing. For instance, many of the code samples in the QuickTime for Java SDK will look for files in the media directory that is in the SDK directory. This media directory is added to the class path when the application is launched. The QTFactory.findAbsolutePath() method is used by the application to find the absolute path of the file, and to find those files, at runtime.
This method searches for the specified path as this path is appended to these known directories. It returns the first occurrence of the file (or directory) that exists in these locations. If the specified file is not found, a FileNotFoundException is thrown.