net.sourceforge.nite.gui.mediaviewer
Class NITEMediaPlayer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JInternalFrame
                  extended by net.sourceforge.nite.gui.mediaviewer.NITEMediaPlayer
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants, PlayingTimeHandler, TimeHandler
Direct Known Subclasses:
NITEAudioPlayer, NITEVideoPlayer

public abstract class NITEMediaPlayer
extends javax.swing.JInternalFrame
implements PlayingTimeHandler

A video player implementation using JMF [DR: Added a line in loadIcon, since the system missed part of the classpath in searching for the icons.]

Author:
judyr, jeanc, jonathan, dennisr BUG FIXES, FEATURE EXTENSIONS jeanc Jan 2004 Added mute button, fixed rewind and fast forward buttons to be labelled properly and to work in first/last five seconds of video, fixed bug whereby the synchronization with a text display didn't work if one went backwards in the video file to replay part of it, fixed time slider so that it updates as video plays; added comments about what else I think should be done to this code. BUG FIXES jonathan Feb 2004. looping bug fixed which was caused by the wrong test being applied in changeState on the TimeSlider; media windows were occasionally starting without a request from the user. This just needed a player.prefetch instead of a player.play call. Stopped exceptions being thrown when file not found - sensible message generated instead; players are now only visible if there's something to play; removed much code duplication from NITEAudioPlayer; sensible default sizes for media windows; grey out play button when end is reached - don't go back to start. JC: Further comments: The green highlighting means "we're in synchronized mode and this tag is at current video time". We need to find a way for this not to interfere with the blue highlighting that means "this is the current selection". It looks inconsistent when one of the currently timed tags which should be green is blue just because it's selected as well. One shouldn't have to select a segment (blue highlight) in order to ctrl-right-click to play it, although that would be OK if we could see both highlights at once. [ jonathan ] I'm sure the above are NTextArea issues. Add play speed slider In my view, if one crtl-right-clicks to play a segment, it should just play and then the system should return to its previous state - playing a segment shouldn't bob up all the other tags that are at the same time in synchronize mode, shouldn't allow for pausing, rewinding, etc., shouldn't reset video (and in synch mode, system) time to the end of the played segment. It ought to be that one can play a video, pause, go back to look at something small, and return to the place where one was. The current code implements playSegment as a special mode of play (so there's a pause button and everything), and that's why the time resetting occurs. We'd need to grey out the play button whilst playing a segment and come up with a different kind of highlight to show which one we were playing if we did reimplement. I haven't tried it because I need to see if my views are contentious first. When the monitor display comes up, there are already some tags highlighted in green, the colour for "this is a tag at the current system time". The wierd thing is that we aren't actually in synchronized mode when the display comes up, so these tags shouldn't be appearing at all (in my view). At the moment, synchronized mode just appears to mean it doesn't highlight tags as one plays. If uncontentious, changes required to NTextArea. Rewind and fast forward work when paused but it's impossible to tell that they do because the video doesn't shift to the correct still picture for the start point until you press play, despite doing a setMediaTime. Can this be fixed? [jonathan] - this works though I don't know when it was fixed or who did it When we get to the end of a video this code automatically goes to the beginning again. I don't like that (and the user can always use the slider to get back to the beginning). I'm pretty sure it's because it's easier to implement that - if it doesn't, then we need another icon for the play button greyed out, because it's not appropriate to play *or* pause in the state that there's no video left. If you decide to change this, search on Time(0). The EndOfMediaEvent instance in ControllerListener is the main one for playing past the end; I'm not sure what exercises the other one (when play is called by a time that's too big). Again, my views could be contentious. [ jonathan ] - play is greyed out by playButton.setEnabled(false). I think I've implemented this request though it could clearly equally be applied to the other buttons I suppose. The implementation was clearly aiming for rewind, fastforward, back one frame, forward one frame, but the last two aren't completely implemented. [Dennis Hofs] Added a rate slider at the bottom of the window. It ranges from -4x (meaning that the media is played 4 times slower than normal) to +4x (the media is played 4 times faster). The default value is 0 (normal play rate). The play rate is computed with an exponential function on the distance of the slider value from 0, so the rate grows faster as the distance of the slider value from 0 increases. The play rate is not changed while the player is playing. A slider change will have its effect when the player is paused and playback is restarted. A Reset button allows the user to reset the rate slider to 0. [jonathan] 5.12.4 Removed the buttons (except Mute) and all the time handling stuff and put it in net.sourceforge.nite.time.ClockFace as a single controlling button-set (making most of the above comments redundant.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JInternalFrame
javax.swing.JInternalFrame.JDesktopIcon
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
 
Fields inherited from class javax.swing.JInternalFrame
CONTENT_PANE_PROPERTY, FRAME_ICON_PROPERTY, GLASS_PANE_PROPERTY, IS_CLOSED_PROPERTY, IS_ICON_PROPERTY, IS_MAXIMUM_PROPERTY, IS_SELECTED_PROPERTY, LAYERED_PANE_PROPERTY, MENU_BAR_PROPERTY, ROOT_PANE_PROPERTY, TITLE_PROPERTY
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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 javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
NITEMediaPlayer(DefaultClock c)
           
NITEMediaPlayer(java.io.File f, DefaultClock c)
           
NITEMediaPlayer(java.io.File f, DefaultClock c, java.lang.String name)
           
 
Method Summary
 void acceptTimeChange(double systemTime)
          skip to the given time
 void acceptTimeChangeWhenPrefetched(double systemTime)
          skip to the given time when ready
 void acceptTimeSpanChange(double start, double end)
          This gets called if we control-right-click to play the currently selected segment.
 void close()
          Closes the media player.
 void controllerUpdate(ControllerEvent event)
          This controllerUpdate function must be defined in order to implement a ControllerListener interface.
 void Exit()
           
 void fastForward()
          fast forward the continuous stream by the specified amount
 void fastForward(int seconds)
          fast forward the continuous stream by the specified amount
 Clock getClock()
          Return the Clock that is currently syncronising this TimeHandler
 java.lang.String getFileName()
          Return the file name being played.
 int getID()
           
 double getMaxTime()
          get the end time of the media - in fact we return 0.0 as we auto-register our time with any clock when we have pre-fetched the media file!
 double getTime()
          get the current media time
 int getWindSkip()
          get the number of seconds the fast-forward and rewind buttons jump
 boolean isMaster()
          return true if this player has the 'master' button checked, and thus controls time for the application
 boolean isPlaying()
          return true if the media is currently playing
 boolean pastEndTime(double ctime)
          return a boolean: true the given time is after the end time of the media file.
 void pause()
          pause the continuous stream
 void play()
          start playing the continuous stream
 void playWhenPrefetched()
          start playing when ready
 void rewind()
          rewind the continuous stream by the pre-defined amount (defaults to 5 seconds)
 void rewind(int seconds)
           
 void setClock(Clock c)
          Set the Clock to which this TimeHandler is registered
 void setID(int i)
           
 void setMaster(boolean mast)
          Make this player control time for the application if the argument is 'true', or stop it from being if 'false'.
 void setMute(boolean val)
          set the mute on or off
 void setPlayRate(float rate)
          set the rate of play so we can sound like pinky and perky.
 void setSendSynchronization(boolean val)
          set the player to send synchronize messages.
 void setTime(double time)
          Broadcast a new time.
 void setTimeHighlightColor(java.awt.Color color)
          Change the Color used for all registered TimeHandlers to highlight times
 void setTimeSpan(double start, double end)
          Broadcast a new span to all registered TimeHandlers.
 void setWindSkip(int seconds)
          set the number of seconds the fast-forward and rewind buttons jump
 
Methods inherited from class javax.swing.JInternalFrame
addInternalFrameListener, dispose, doDefaultCloseAction, getAccessibleContext, getContentPane, getDefaultCloseOperation, getDesktopIcon, getDesktopPane, getFocusCycleRootAncestor, getFocusOwner, getFrameIcon, getGlassPane, getInternalFrameListeners, getJMenuBar, getLayer, getLayeredPane, getMenuBar, getMostRecentFocusOwner, getNormalBounds, getRootPane, getTitle, getUI, getUIClassID, getWarningString, hide, isClosable, isClosed, isFocusCycleRoot, isIcon, isIconifiable, isMaximizable, isMaximum, isResizable, isSelected, moveToBack, moveToFront, pack, remove, removeInternalFrameListener, reshape, restoreSubcomponentFocus, setClosable, setClosed, setContentPane, setDefaultCloseOperation, setDesktopIcon, setFocusCycleRoot, setFrameIcon, setGlassPane, setIcon, setIconifiable, setJMenuBar, setLayer, setLayer, setLayeredPane, setLayout, setMaximizable, setMaximum, setMenuBar, setNormalBounds, setResizable, setSelected, setTitle, setUI, show, toBack, toFront, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, 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, 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, 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, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NITEMediaPlayer

public NITEMediaPlayer(DefaultClock c)

NITEMediaPlayer

public NITEMediaPlayer(java.io.File f,
                       DefaultClock c)

NITEMediaPlayer

public NITEMediaPlayer(java.io.File f,
                       DefaultClock c,
                       java.lang.String name)
Method Detail

isMaster

public boolean isMaster()
return true if this player has the 'master' button checked, and thus controls time for the application

Specified by:
isMaster in interface PlayingTimeHandler

setMaster

public void setMaster(boolean mast)
Make this player control time for the application if the argument is 'true', or stop it from being if 'false'.

Specified by:
setMaster in interface PlayingTimeHandler

pastEndTime

public boolean pastEndTime(double ctime)
return a boolean: true the given time is after the end time of the media file.

Specified by:
pastEndTime in interface PlayingTimeHandler

getTime

public double getTime()
get the current media time

Specified by:
getTime in interface PlayingTimeHandler

play

public void play()
Description copied from interface: PlayingTimeHandler
start playing the continuous stream

Specified by:
play in interface PlayingTimeHandler

pause

public void pause()
Description copied from interface: PlayingTimeHandler
pause the continuous stream

Specified by:
pause in interface PlayingTimeHandler

rewind

public void rewind(int seconds)
Specified by:
rewind in interface PlayingTimeHandler

rewind

public void rewind()
Description copied from interface: PlayingTimeHandler
rewind the continuous stream by the pre-defined amount (defaults to 5 seconds)

Specified by:
rewind in interface PlayingTimeHandler

setPlayRate

public void setPlayRate(float rate)
set the rate of play so we can sound like pinky and perky. 1 is normal.

Specified by:
setPlayRate in interface PlayingTimeHandler

fastForward

public void fastForward()
Description copied from interface: PlayingTimeHandler
fast forward the continuous stream by the specified amount

Specified by:
fastForward in interface PlayingTimeHandler

fastForward

public void fastForward(int seconds)
Description copied from interface: PlayingTimeHandler
fast forward the continuous stream by the specified amount

Specified by:
fastForward in interface PlayingTimeHandler

isPlaying

public boolean isPlaying()
return true if the media is currently playing

Specified by:
isPlaying in interface PlayingTimeHandler

acceptTimeChangeWhenPrefetched

public void acceptTimeChangeWhenPrefetched(double systemTime)
skip to the given time when ready


playWhenPrefetched

public void playWhenPrefetched()
start playing when ready


acceptTimeChange

public void acceptTimeChange(double systemTime)
skip to the given time

Specified by:
acceptTimeChange in interface TimeHandler

acceptTimeSpanChange

public void acceptTimeSpanChange(double start,
                                 double end)
This gets called if we control-right-click to play the currently selected segment.

Specified by:
acceptTimeSpanChange in interface TimeHandler

setTimeSpan

public void setTimeSpan(double start,
                        double end)
Description copied from interface: TimeHandler
Broadcast a new span to all registered TimeHandlers.

Specified by:
setTimeSpan in interface TimeHandler

setTime

public void setTime(double time)
Description copied from interface: TimeHandler
Broadcast a new time. Implement by sending a setSystemTime call to the current Clock.

Specified by:
setTime in interface TimeHandler

getClock

public Clock getClock()
Description copied from interface: TimeHandler
Return the Clock that is currently syncronising this TimeHandler

Specified by:
getClock in interface TimeHandler

setTimeHighlightColor

public void setTimeHighlightColor(java.awt.Color color)
Description copied from interface: TimeHandler
Change the Color used for all registered TimeHandlers to highlight times

Specified by:
setTimeHighlightColor in interface TimeHandler

setClock

public void setClock(Clock c)
Description copied from interface: TimeHandler
Set the Clock to which this TimeHandler is registered

Specified by:
setClock in interface TimeHandler

controllerUpdate

public void controllerUpdate(ControllerEvent event)
This controllerUpdate function must be defined in order to implement a ControllerListener interface. This function will be called whenever there is a media event


setSendSynchronization

public void setSendSynchronization(boolean val)
set the player to send synchronize messages. This is a backward compatibility aid: in fact we can only select on the clock interface whether all the text areas are synced or not..


close

public void close()

Closes the media player. This method should be called when the media player is not needed anymore.


Exit

public void Exit()

getID

public int getID()

setID

public void setID(int i)

setWindSkip

public void setWindSkip(int seconds)
set the number of seconds the fast-forward and rewind buttons jump


getWindSkip

public int getWindSkip()
get the number of seconds the fast-forward and rewind buttons jump


setMute

public void setMute(boolean val)
set the mute on or off


getMaxTime

public double getMaxTime()
get the end time of the media - in fact we return 0.0 as we auto-register our time with any clock when we have pre-fetched the media file!

Specified by:
getMaxTime in interface TimeHandler

getFileName

public java.lang.String getFileName()
Return the file name being played.

Specified by:
getFileName in interface PlayingTimeHandler