home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / jisapplet / src / jisapplet.java
Encoding:
Java Source  |  2000-09-28  |  2.2 KB  |  77 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.net.*;
  9. import java.applet.Applet;
  10. import java.awt.*;
  11. import java.io.*;
  12.  
  13. import quicktime.*;
  14. import quicktime.io.QTFile;
  15.  
  16. import quicktime.app.QTFactory;
  17. import quicktime.app.display.*;
  18. import quicktime.app.image.ImageDrawer;
  19. import quicktime.std.StdQTConstants;
  20.  
  21. // plays sound from a zip file asynchronously, i.e., in a Thread
  22.  
  23. import quicktime.*;
  24.  
  25. public class JISApplet extends Applet {
  26.     private Drawable myQTContent;
  27.     private QTCanvas myQTCanvas;
  28.     
  29.     public void init () {
  30.         try {
  31.             // this is a workaround required by a bug in the loading
  32.             // mechanism of applets using the JavaPlugin on Netscape on Win
  33.             if (QTSession.isInitialized() == false)
  34.                 QTSession.open();
  35.             
  36.                 // set up a QTCanvas which will disply its content 
  37.                 // at its original size of smaller and centered in the space given
  38.                 // to the QTCanvas when the applet is layed out
  39.             setLayout (new BorderLayout());
  40.             myQTCanvas = new QTCanvas (QTCanvas.kInitialSize, 0.5F, 0.5F);
  41.             add (myQTCanvas, "Center");        
  42.                 
  43.                 //our media is in the local directory
  44.             QTFile file = new QTFile (getCodeBase().getFile() + getParameter("media"));
  45.             myQTContent = QTFactory.makeDrawable (new FileInputStream(file), StdQTConstants.kDataRefFileExtensionTag, getParameter("ext"));
  46.         } catch (QTException qtE) {
  47.             qtE.printStackTrace();
  48.                 // something wrong with the content but QT itself is OK
  49.             if (QTSession.isInitialized())
  50.                 myQTContent = ImageDrawer.getQTLogo();
  51.             else
  52.                 throw new RuntimeException (qtE.getMessage());
  53.         } catch (IOException ioE) {
  54.             ioE.printStackTrace();
  55.             myQTContent = ImageDrawer.getQTLogo();
  56.         }
  57.     }    
  58.  
  59.     public void start () { 
  60.         try { // if QT was not successfully initialized the QTCanvas will be null
  61.             if (myQTCanvas != null)
  62.                 myQTCanvas.setClient (myQTContent, true);            
  63.         } catch (QTException e) {
  64.             e.printStackTrace();
  65.         }
  66.     }
  67.     
  68.     public void stop () { 
  69.         if (myQTCanvas != null)
  70.             myQTCanvas.removeClient();
  71.     }
  72.     
  73.     public void destroy () {
  74.         QTSession.close();
  75.     }
  76. }
  77.