A good starting point for understanding QuickTime for Java is the QTSimpleApplet program from the QuickTime for Java SDK. The code listing for QTSimpleApplet.java is given below:
/* * QuickTime for Java SDK Sample Code Usage subject to restrictions in SDK License Agreement * Copyright: © 1996-1999 Apple Computer, Inc. */ import java.applet.Applet; import java.awt.*; import java.io.*; import quicktime.*; import quicktime.io.QTFile; import quicktime.app.QTFactory; import quicktime.app.display.*; import quicktime.app.image.ImageDrawer; // for exceptions public class QTSimpleApplet extends Applet { private Drawable myQTContent; private QTCanvas myQTCanvas; public void init () { try { // this is a workaround required by a bug in the loading // mechanism of applets using the JavaPlugin on Netscape on Win if (QTSession.isInitialized() == false) QTSession.open(); // set up a QTCanvas which will disply its content // at its original size of smaller and centered in the space given // to the QTCanvas when the applet is layed out setLayout (new BorderLayout()); myQTCanvas = new QTCanvas (QTCanvas.kInitialSize, 0.5F, 0.5F); add (myQTCanvas, "Center"); QTFile file = new QTFile (getCodeBase().getFile() + getParameter("file")); myQTContent = QTFactory.makeDrawable (file); } catch (QTException qtE) { // something wrong with the content but QT itself is OK if (QTSession.isInitialized()) myQTContent = ImageDrawer.getQTLogo(); else throw new RuntimeException (qtE.getMessage()); } catch (FileNotFoundException fnfE) { myQTContent = ImageDrawer.getQTLogo(); } catch (IOException ioE) { // the IOException would occur as a violation of // java security settings on the user machine - throw it again throw new SecurityException (ioE.getMessage()); } } public void start () { try { // if QT was not successfully initialized the QTCanvas will be null if (myQTCanvas != null) myQTCanvas.setClient (myQTContent, true); } catch (QTException e) { e.printStackTrace(); } } public void stop () { if (myQTCanvas != null) myQTCanvas.removeClient(); } public void destroy () { QTSession.close(); } }
The out of QTSimpleApplet running in an applet viewer is shown in Fig. 9.1.
{\tt QTSimpleApplet} Output
The things to note about this program are:<applet code="QTSimpleApplet.class" width=200 height=100> <param name="file" value="sample.mov"> </applet>
The basic operation of the code is as follows:
setLayout (new BorderLayout()); myQTCanvas = new QTCanvas (QTCanvas.kInitialSize, 0.5F, 0.5F); add (myQTCanvas, "Center"); QTFile file = new QTFile (getCodeBase().getFile() + getParameter("file")); myQTContent = QTFactory.makeDrawable (file); } catch (Exception e) { e.printStackTrace(); ... } }
<PARAM>
tag in the call from the HTML file.
public void start () { try { my QTCanvas.setClient (myQTContent, true); } catch (Exception e) { e.printStackTrace(); } }
public void stop () { my QTCanvas.removeClient(); } public void destroy () { QTSession.close(); }