home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-01-28 | 5.6 KB | 220 lines |
- // Copyright (c) Oracle Corporation 1997. All Rights Reserved.
- //
- // Package oracle.ovc - Oracle Video Client for Java
- //
- // CtntList.java - This example demonstrates the ContentQuery feature.
- //
-
- // Sun JDK Imports
- import java.awt.*;
- import java.awt.event.*;
-
-
- // Oracle Video Client Imports
- import oracle.ovc.*;
-
- public class CtntList extends WindowAdapter
- implements PlayerListener, ItemListener
- {
- Player player = null;
- Component playerUI = null;
- Frame playerframe = null;
- StmOpts m_opts = null;
- String m_MediaFile = null;
- boolean m_Loop = true;
- boolean m_AutoStart = false;
- String m_PlayTo = "end";
- String m_PlayFrom = "beginning";
- String m_oldState = null;
- Choice choice;
-
- public static void main (String args[])
- {
- CtntList app = new CtntList ();
- app.playerframe = new Frame ("CtntList");
-
- app.playerframe.setBackground(Color.lightGray);
- app.playerframe.setSize(360, 340);
- app.playerframe.addWindowListener(app);
-
- app.addPlayer();
-
- try
- {
- app.player.addListener (app);
- }
- catch (PlayerException e)
- {
- System.out.println("addListener() failed: " + e);
- }
-
- app.addContentList();
-
- app.m_MediaFile = app.choice.getSelectedItem();
- if (app.m_MediaFile != null)
- {
- System.out.println(" loading: " + app.m_MediaFile);
- app.loadMediaFile();
- }
- }
-
- public void addContentList()
- {
- int i;
- StmInfo[] contentList;
- ContentIter iter;
-
- choice = new Choice();
- choice.addItemListener(this);
- playerframe.add("South",choice);
- playerframe.show();
-
- iter = new ContentIter(0, 10);
-
- try
- {
- while (iter.m_pos!=-1)
- {
- System.out.println("calling query() with iter = { " +
- iter.m_pos + " , " + iter.m_num + " }");
- contentList = Content.query(null,"*",iter);
- System.out.println("query() returned with iter = { " +
- iter.m_pos + " , " + iter.m_num + " }");
-
- for(i=0; i<iter.m_num;i++)
- choice.addItem(contentList[i].m_url);
- }
- }
- catch ( ContentException e )
- {
- System.out.println("ContentException raised: " + e);
- }
-
-
- }
-
- // addPlayer() - create playback player and add to frame
- public void addPlayer()
- {
- // create player
- try
- {
- player = PlayerFactory.getPlayer ();
- }
- catch ( UnsatisfiedLinkError e )
- {
- System.out.println(e.getMessage());
- }
- catch ( PlayerException e )
- {
- System.out.println("Unable to create a Player object. " + e);
- }
-
- // init player UI
- try
- {
- playerUI = player.getPlayerUI ();
- }
- catch ( PlayerException e )
- {
- System.out.println("getPlayerUI failed: " + e);
- }
-
- // Add the visual component of the player object to the frame
- playerframe.add (playerUI);
- }
-
- // itemStateChanged() - callback from Choice list
- public void itemStateChanged(ItemEvent event)
- {
- // note: only listening for choice box
- m_MediaFile = choice.getSelectedItem();
-
- System.out.println("loading: " + m_MediaFile);
- loadMediaFile();
- }
-
- // loadMediaFile() - routine to actual load stream for playback
- public void loadMediaFile()
- {
- m_opts = new StmOpts();
- m_opts.m_loop = m_Loop;
- m_opts.m_autoStart = m_AutoStart;
- m_opts.m_playFrom = StmPos.fromString(m_PlayFrom);
- m_opts.m_playTo = StmPos.fromString(m_PlayTo);
-
- // Load and prepare the default video for playback
- // with given stream options.
- try
- {
- if (player.getState() != Player.ST_INIT)
- player.unload();
- player.load (m_MediaFile, m_opts);
- }
- catch ( PlayerException e )
- {
- System.out.println("Could not load content: " + e);
- }
- }
-
- //
- // PlayerListener Routines
- //
-
- public void stateChange(int newState)
- {
- String st;
-
- switch (newState)
- {
- case Player.ST_UNINIT: st = "uninitialized"; break;
- case Player.ST_INIT: st = "initialized"; break;
- case Player.ST_PREPARED: st = "prepared"; break;
- case Player.ST_REALIZED: st = "realized"; break;
- case Player.ST_PLAYING: st = "playing"; break;
- case Player.ST_PAUSED: st = "paused"; break;
- case Player.ST_EOS: st = "end of stream"; break;
- case Player.ST_ERROR: st = "error"; break;
- default: st = "unknown (" + newState + ")" ; break;
- }
-
- System.out.println("state change: " + m_oldState + " -> " + st);
- m_oldState = st;
- }
-
- public void error(int code, String msg)
- {
- System.out.println("OVC-" + code + ": " + msg);
- }
-
- public void endOfStream()
- {
- System.out.println("end of stream reached");
- }
-
- //
- // WindowAdapter routines
- //
-
- public void windowClosing(WindowEvent event)
- {
- System.out.println("Shutting down the java client ...");
-
- if (CtntList.player != null)
- {
- try
- {
- System.out.println("Player state before exiting: " +
- CtntList.player.getState());
- CtntList.player.term ();
- }
- catch (PlayerException e)
- {
- System.out.println("Error while terminating player: " + e);
- }
- }
- System.exit(0);
- }
- }
-
-