home *** CD-ROM | disk | FTP | other *** search
/ Oracle Video Server 3.0.3.1 / OracleVideoClient3.0.3.iso / java / simple.java < prev   
Encoding:
Java Source  |  1998-01-28  |  3.4 KB  |  128 lines

  1. // Copyright (c) Oracle Corporation 1997.  All Rights Reserved.
  2. // 
  3. // Package oracle.ovc - Oracle Video Client for Java
  4. //
  5. // Simple.java - This example demonstrates the basic Player object.
  6.  
  7. // Sun JDK Imports
  8. import java.awt.*;
  9. import java.awt.event.*;
  10.  
  11.  
  12. // Oracle Video Client Imports
  13. import oracle.ovc.PlayerFactory;
  14. import oracle.ovc.PlayerException;
  15. import oracle.ovc.Player;
  16.  
  17.  
  18. public class Simple 
  19. {
  20.      static Player    player            = null;
  21.      static Component playerUI          = null;
  22.      static Frame     playerframe       = null;
  23.  
  24.      static String    m_MediaFile       = "/mds/video/ovs_mpg1_2048k.mpi";
  25.      static int       m_Width           = 360;
  26.      static int       m_Height          = 311;
  27.  
  28.      public static void main (String args[])
  29.      {
  30.          Simple app = new Simple ();
  31.          playerframe = new PlayerFrame ("OVPlayer", m_Width, m_Height);
  32.          
  33.          app.addPlayer();
  34.  
  35.          app.loadMediaFile();
  36.  
  37.      } // end of main
  38.  
  39.  
  40.      public void addPlayer()
  41.      {
  42.          //  Create a player object.
  43.          try {
  44.              player = PlayerFactory.getPlayer ();
  45.          }
  46.          catch ( UnsatisfiedLinkError e ) {
  47.              System.out.println(e.getMessage());
  48.          }
  49.          catch ( PlayerException e ) {
  50.              System.out.println("Unable to create a Player object: " + e);
  51.          }
  52.  
  53.          //  Create the visual playback component of the player object.
  54.          try {
  55.              playerUI = player.getPlayerUI ();
  56.          }
  57.          catch ( PlayerException e ) {
  58.              System.out.println("exception in getPlayerUI: " + e);
  59.          }
  60.  
  61.          //  Add the visual component of the player object
  62.          //  to the frame.
  63.            playerframe.add (playerUI);
  64.          playerframe.show ();
  65.  
  66.      } // end of addPlayer
  67.  
  68.  
  69.     public void loadMediaFile()
  70.     {
  71.          //  Load and prepare the default video for playback
  72.          //  with default stream options.
  73.          try {
  74.              player.load (m_MediaFile, null);
  75.          }
  76.          catch ( PlayerException e ) {
  77.              System.out.println("Could not load content: " + e);
  78.          }
  79.      } // end of initial_load
  80.  
  81. }  // end of Simple class
  82.  
  83.  
  84. class PlayerFrame extends Frame
  85. {     
  86.      public PlayerFrame (String title, int m_Width, int m_Height)
  87.      {
  88.          super (title);
  89.  
  90.          //   Register a Windowlistener after creating the frame, 
  91.          //   the listener is required to exit properly from the app.
  92.          addWindowListener(new PFAdapter());
  93.  
  94.          setSize (m_Width, m_Height);
  95.  
  96.      } // end of constructor
  97.  
  98. }  // end of class
  99.  
  100.  
  101. class PFAdapter extends WindowAdapter 
  102. {
  103.      public void windowClosing(WindowEvent event)
  104.      {
  105.            System.out.println("Shutting down the java client ...");
  106.  
  107.            if (Simple.player != null)
  108.            {
  109.          try { 
  110.          System.out.println("Player state before exiting: " + Simple.player.getState());
  111.  
  112.                  //  Unload the video before exiting, thereby
  113.                  //  releasing any resources associated with the current stream.
  114.                  Simple.player.unload ();
  115.                  Simple.player.term ();
  116.              } 
  117.              catch (PlayerException e) {
  118.                  System.out.println("exception while unloading: " + e);
  119.              }
  120.           }
  121.      
  122.       System.exit(0);
  123.  
  124.       } // end of windowClosing
  125.  
  126. } // end of PFAdapter
  127.  
  128.