home *** CD-ROM | disk | FTP | other *** search
/ Oracle Video Server 3.0.3.1 / OracleVideoClient3.0.3.iso / java / ctntlist.java < prev    next >
Encoding:
Java Source  |  1998-01-28  |  5.6 KB  |  220 lines

  1. // Copyright (c) Oracle Corporation 1997.  All Rights Reserved.
  2. // 
  3. // Package oracle.ovc - Oracle Video Client for Java
  4. //
  5. // CtntList.java - This example demonstrates the ContentQuery feature.
  6. //
  7.  
  8. // Sun JDK Imports
  9. import java.awt.*;
  10. import java.awt.event.*;
  11.  
  12.  
  13. // Oracle Video Client Imports
  14. import oracle.ovc.*;
  15.  
  16. public class CtntList extends WindowAdapter
  17.                       implements PlayerListener, ItemListener
  18. {
  19.   Player      player            = null;
  20.   Component   playerUI          = null;
  21.   Frame       playerframe       = null;
  22.   StmOpts     m_opts            = null;
  23.   String      m_MediaFile       = null;
  24.   boolean     m_Loop            = true;
  25.   boolean     m_AutoStart       = false;
  26.   String      m_PlayTo          = "end";
  27.   String      m_PlayFrom        = "beginning";
  28.   String      m_oldState        = null;
  29.   Choice      choice;
  30.  
  31.   public static void main (String args[])
  32.   {
  33.     CtntList app = new CtntList ();
  34.     app.playerframe = new Frame ("CtntList");
  35.  
  36.     app.playerframe.setBackground(Color.lightGray);
  37.     app.playerframe.setSize(360, 340);
  38.     app.playerframe.addWindowListener(app);
  39.  
  40.     app.addPlayer();
  41.  
  42.     try 
  43.     {
  44.       app.player.addListener (app);
  45.     }
  46.     catch (PlayerException e) 
  47.     {
  48.       System.out.println("addListener() failed: " + e);
  49.     }
  50.  
  51.     app.addContentList();
  52.  
  53.     app.m_MediaFile = app.choice.getSelectedItem();
  54.     if (app.m_MediaFile != null)
  55.     {   
  56.       System.out.println(" loading: " + app.m_MediaFile);
  57.       app.loadMediaFile();  
  58.     }
  59.   }
  60.  
  61.   public void addContentList()
  62.   {
  63.     int i;
  64.     StmInfo[] contentList;
  65.     ContentIter iter;
  66.  
  67.     choice = new Choice();
  68.     choice.addItemListener(this);
  69.     playerframe.add("South",choice);
  70.     playerframe.show();
  71.  
  72.     iter = new ContentIter(0, 10);
  73.  
  74.     try 
  75.     {
  76.       while (iter.m_pos!=-1)
  77.       {
  78.         System.out.println("calling query() with iter = { " +
  79.                            iter.m_pos + " , " + iter.m_num + " }");
  80.         contentList = Content.query(null,"*",iter);
  81.         System.out.println("query() returned with iter = { " +
  82.                            iter.m_pos + " , " + iter.m_num + " }");
  83.  
  84.         for(i=0; i<iter.m_num;i++)
  85.           choice.addItem(contentList[i].m_url);
  86.       }
  87.     }
  88.     catch ( ContentException e )
  89.     {
  90.       System.out.println("ContentException raised: " + e);
  91.     }
  92.  
  93.  
  94.   }
  95.  
  96.   // addPlayer() - create playback player and add to frame
  97.   public void addPlayer()
  98.   {
  99.     // create player
  100.     try
  101.     {
  102.       player = PlayerFactory.getPlayer ();
  103.     }
  104.     catch ( UnsatisfiedLinkError e )
  105.     {
  106.       System.out.println(e.getMessage());
  107.     }
  108.     catch ( PlayerException e )
  109.     {
  110.       System.out.println("Unable to create a Player object. " + e);
  111.     }
  112.  
  113.     // init player UI
  114.     try
  115.     {
  116.       playerUI = player.getPlayerUI ();
  117.     }
  118.     catch ( PlayerException e )
  119.     {
  120.       System.out.println("getPlayerUI failed: " + e);
  121.     }
  122.  
  123.     //  Add the visual component of the player object to the frame
  124.     playerframe.add (playerUI);
  125.   }
  126.  
  127.   // itemStateChanged() - callback from Choice list
  128.   public void itemStateChanged(ItemEvent event)
  129.   {
  130.     // note: only listening for choice box
  131.     m_MediaFile = choice.getSelectedItem();
  132.         
  133.     System.out.println("loading: " + m_MediaFile);
  134.     loadMediaFile();  
  135.   }
  136.  
  137.   // loadMediaFile() - routine to actual load stream for playback
  138.   public void loadMediaFile()
  139.   {
  140.     m_opts             = new StmOpts();
  141.     m_opts.m_loop      = m_Loop;
  142.     m_opts.m_autoStart = m_AutoStart;
  143.     m_opts.m_playFrom  = StmPos.fromString(m_PlayFrom);
  144.     m_opts.m_playTo    = StmPos.fromString(m_PlayTo);
  145.  
  146.     //  Load and prepare the default video for playback
  147.     //  with given stream options.
  148.     try
  149.     {
  150.     if (player.getState() != Player.ST_INIT)
  151.           player.unload();
  152.         player.load (m_MediaFile, m_opts);
  153.     }
  154.     catch ( PlayerException e )
  155.     {
  156.       System.out.println("Could not load content: " + e);
  157.     }
  158.   }
  159.  
  160.   //
  161.   // PlayerListener Routines
  162.   //
  163.  
  164.   public void stateChange(int newState)
  165.   {
  166.     String st;
  167.     
  168.     switch (newState)
  169.     {
  170.     case Player.ST_UNINIT:    st = "uninitialized";                break;
  171.     case Player.ST_INIT:      st = "initialized";                  break;
  172.     case Player.ST_PREPARED:  st = "prepared";                     break;
  173.     case Player.ST_REALIZED:  st = "realized";                     break;
  174.     case Player.ST_PLAYING:   st = "playing";                      break;
  175.     case Player.ST_PAUSED:    st = "paused";                       break;
  176.     case Player.ST_EOS:       st = "end of stream";                break;
  177.     case Player.ST_ERROR:     st = "error";                        break;
  178.     default:                  st = "unknown (" + newState + ")" ;  break;
  179.     }
  180.       
  181.     System.out.println("state change: " + m_oldState + " -> " + st);
  182.     m_oldState = st;
  183.   }
  184.  
  185.   public void error(int code, String msg)
  186.   {
  187.     System.out.println("OVC-" + code + ": " + msg);
  188.   }
  189.  
  190.   public void endOfStream()
  191.   {
  192.     System.out.println("end of stream reached");
  193.   }
  194.  
  195.   //
  196.   // WindowAdapter routines
  197.   //
  198.  
  199.   public void windowClosing(WindowEvent event)
  200.   {
  201.     System.out.println("Shutting down the java client ...");
  202.  
  203.     if (CtntList.player != null)
  204.     {
  205.       try
  206.       {
  207.         System.out.println("Player state before exiting: " +
  208.                CtntList.player.getState());
  209.         CtntList.player.term ();
  210.       } 
  211.       catch (PlayerException e)
  212.       {
  213.         System.out.println("Error while terminating player: " + e);
  214.       }
  215.     }
  216.     System.exit(0);
  217.   }
  218. }
  219.  
  220.