edu.ucsb.nmsl.tools
Class CaptionedMediaPlayer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by edu.ucsb.nmsl.tools.CaptionedMediaPlayer
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.media.ControllerListener

public class CaptionedMediaPlayer
extends javax.swing.JPanel
implements javax.media.ControllerListener, java.awt.event.ActionListener

This class is reponsible for aggregating a Player object and an XML file containing captions and playing those captions back with synchronized with a media file. Currently the format of the XML file is that set by QAD, however, this may change to SMIL in the near future.

Version:
1.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
(package private)  javax.xml.parsers.DocumentBuilder builder
          The DocumentBuilder object used for parsing the caption XML file.
(package private)  javax.swing.JTextPane caption
          The JTextPane object that displays the captions.
protected static int CAPTION_ELEMENT_INDEX
          First element of the caption file.
(package private)  int captionIndex
          Index of the current caption.
(package private)  java.util.Vector captionList
          The list of captions and their times.
(package private)  org.w3c.dom.Document captions
          The Document object that actually contains the caption XML file.
protected static java.lang.String CAPTIONS_ELEMENT_NAME
          Name of captions element in XML file.
(package private)  javax.swing.Timer captionTimer
          The timer that is used to synchronize the media and the caption text.
(package private)  java.awt.Container container
          The Container object that holds the captions and media controls.
protected static java.lang.String LANGUAGE_ELEMENT_NAME
          Name of the language element in XML file.
protected static int MILLISECONDS_PER_SECOND
          Number of milliseconds per second.
(package private)  javax.media.Player player
          The player object from JMF to play the media file.
protected static int PREFERRED_CAPTION_HEIGHT
          Preferred height of the Swing widget that displays the caption.
protected static double SUPPORTED_MEDIA_RATE
           
protected static java.lang.String TEXT_ATTRIBUTE_NAME
          Name of the text attribute in XML file.
protected static java.lang.String TIME_ELEMENT_NAME
          Name of the time stamp element in XML file.
protected static java.lang.String VALUE_ATTRIBUTE_NAME
          Name of the value attribute in XML file.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CaptionedMediaPlayer()
          The default constuctor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          ActionListener method that is called whenever a timeout occurs.
 void controllerUpdate(javax.media.ControllerEvent event)
          Listener method that reacts to media events from the player.
protected  int findCaptionIndex(double now)
          A helper function that finds the caption closest to the time given with in the media stream.
static void main(java.lang.String[] argv)
          Instantiates the CaptionedMediaPlayer and parses the command line arguments to make sure the right number of arguments are passed in.
protected  void parseCaptions(org.w3c.dom.Document doc)
          Helper method that parses the XML file and stores each caption in a vector.
 void play(javax.media.Player p, org.w3c.dom.Document c)
          This method is called to play a media file along with its captions.
 void stop()
          This method is called when the media playing is stopped.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

player

javax.media.Player player
The player object from JMF to play the media file.


caption

javax.swing.JTextPane caption
The JTextPane object that displays the captions.


container

java.awt.Container container
The Container object that holds the captions and media controls.


builder

javax.xml.parsers.DocumentBuilder builder
The DocumentBuilder object used for parsing the caption XML file.


captions

org.w3c.dom.Document captions
The Document object that actually contains the caption XML file.


captionList

java.util.Vector captionList
The list of captions and their times.


captionIndex

int captionIndex
Index of the current caption.


captionTimer

javax.swing.Timer captionTimer
The timer that is used to synchronize the media and the caption text.


CAPTIONS_ELEMENT_NAME

protected static final java.lang.String CAPTIONS_ELEMENT_NAME
Name of captions element in XML file. Each child of the captions element represents an individual caption

See Also:
Constant Field Values

TIME_ELEMENT_NAME

protected static final java.lang.String TIME_ELEMENT_NAME
Name of the time stamp element in XML file. This element represents the time-stamp of a caption

See Also:
Constant Field Values

LANGUAGE_ELEMENT_NAME

protected static final java.lang.String LANGUAGE_ELEMENT_NAME
Name of the language element in XML file. This element represents the language of the text of the caption

See Also:
Constant Field Values

TEXT_ATTRIBUTE_NAME

protected static final java.lang.String TEXT_ATTRIBUTE_NAME
Name of the text attribute in XML file. This attribute represents the text of the caption.

See Also:
Constant Field Values

VALUE_ATTRIBUTE_NAME

protected static final java.lang.String VALUE_ATTRIBUTE_NAME
Name of the value attribute in XML file. This attribute represents the text of the caption.

See Also:
Constant Field Values

CAPTION_ELEMENT_INDEX

protected static final int CAPTION_ELEMENT_INDEX
First element of the caption file.

See Also:
Constant Field Values

PREFERRED_CAPTION_HEIGHT

protected static final int PREFERRED_CAPTION_HEIGHT
Preferred height of the Swing widget that displays the caption.

See Also:
Constant Field Values

MILLISECONDS_PER_SECOND

protected static final int MILLISECONDS_PER_SECOND
Number of milliseconds per second.

See Also:
Constant Field Values

SUPPORTED_MEDIA_RATE

protected static final double SUPPORTED_MEDIA_RATE
See Also:
Constant Field Values
Constructor Detail

CaptionedMediaPlayer

public CaptionedMediaPlayer()
The default constuctor. Creates all the containers for the GUI. No media is read yet.

Method Detail

parseCaptions

protected void parseCaptions(org.w3c.dom.Document doc)
Helper method that parses the XML file and stores each caption in a vector. This method creates a new vector each time.

Parameters:
doc - The XML document object (specfically DOM) that contains the captions.

play

public void play(javax.media.Player p,
                 org.w3c.dom.Document c)
This method is called to play a media file along with its captions. The media file is any media file accepted by JMF 2.1.1e and the caption file is an XML file with a scheme designed by QAD. This scheme may soon become SMIL.

Parameters:
p - The Player object from JMF that plays the media.
c - Document object that holds the caption information.

stop

public void stop()
This method is called when the media playing is stopped.


findCaptionIndex

protected int findCaptionIndex(double now)
A helper function that finds the caption closest to the time given with in the media stream. This a down and dirty linear search and allows for the correct caption to be displayed when the media controls are changed.

Parameters:
now - The current time the media player is at.
Returns:
The index of the caption whose time is <= now, -1 otherwise.

controllerUpdate

public void controllerUpdate(javax.media.ControllerEvent event)
Listener method that reacts to media events from the player. These events include realization, start, stop and end of media.

Specified by:
controllerUpdate in interface javax.media.ControllerListener
Parameters:
event - The controller event that occurred.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
ActionListener method that is called whenever a timeout occurs. This method allows for the synchronization of media and captions. However, be careful, there is no way to differentiate Timer events with other actions. This is a crude way to synchronize the media and captions, but it will do for now.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - The ActionEvent corresponding to a timeout (hopefully).

main

public static void main(java.lang.String[] argv)
Instantiates the CaptionedMediaPlayer and parses the command line arguments to make sure the right number of arguments are passed in. The first command line argument is assumed to be the media file, and the second the caption file in the form of an XML file.

Parameters:
argv - The command line arguments