Copyright 2011-01-06 Werner Randelshofer

ch.randelshofer.media
Class AbstractPlayer

java.lang.Object
  extended by ch.randelshofer.media.AbstractPlayer
All Implemented Interfaces:
Player, StateModel, java.lang.Runnable
Direct Known Subclasses:
ANIMPlayer, PBMPlayer, SEQPlayer

public abstract class AbstractPlayer
extends java.lang.Object
implements Player, java.lang.Runnable

Generic interface for media players.

Version:
2.1 2009-12-25 Added support for color cycling.
2.0.1 2009-11-23 Removed unused imports.
2.0 2005-07-09 Uses now a SequentialDispatcher for multithreading instead of individual threads. The SequentialDispatcher guarantees, that all animation steps are performed sequentially. This removes the need for clients to wait until a specific state has been reached, before they can request another state from the player.
1.1 2002-02-06 Support for ChangeListeners added.
1.0 1999-10-19
Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland

Field Summary
protected  SequentialDispatcher dispatcher
          The dispatcher.
protected  javax.swing.event.EventListenerList listenerList
          Listener support.
protected  java.beans.PropertyChangeSupport propertyChangeSupport
          Support for property change listeners.
 
Fields inherited from interface ch.randelshofer.media.Player
CLOSED, PREFETCHED, PREFETCHING, REALIZED, REALIZING, STARTED, UNREALIZED
 
Constructor Summary
AbstractPlayer()
          Creates a new instance.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener listener)
          Adds a listener that wants to be notified about state changes of the player.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a listener who is interested in changes of this object.
 void addStateListener(StateListener l)
          Adds a listener that wants to be notified about state changes of the player.
 void close()
          Initiates the following asynchronous state transitions: any state -> closed
 void deallocate()
          Initiates the following asynchronous state transitions: realizing -> unrealized prefetching -> realized prefetched -> realized realized started -> throws IllegalStateException closed -> throws IllegalStateException
protected abstract  void doClosed()
          Does the work for the closed state.
protected abstract  void doPrefetched()
          Does the work for the prefetched state.
protected abstract  void doPrefetching()
          Does the work for the prefetching state.
protected abstract  void doRealized()
          Does the work for the realized state.
protected abstract  void doRealizing()
          Does the work for the realizing state.
protected abstract  void doStarted()
          Does the work for the started state.
protected abstract  void doUnrealized()
          Does the work for the unrealized state.
protected  void fireStateChanged(int newState)
          Notifies all registered state listeners and all registered change listeners.
 int getState()
          Gets the current state of the player.
 int getTargetState()
          Gets the target state.
 boolean isActive()
          Returns true when the target state of the player is equal to STARTED.
 void prefetch()
          Initiates the following asynchronous state transitions: unrealized -> realizing -> realized -> prefetching -> prefetched realizing -> realized -> prefetching -> prefetched realized -> prefetching -> prefetched prefetching -> prefetched prefetched started -> throws IllegalStateException closed -> throws IllegalStateException
 void realize()
          Initiates the following asynchronous state transitions: unrealized -> realizing -> realized realizing -> realized realized started -> throws IllegalStateException closed -> throws IllegalStateException
 void removeChangeListener(javax.swing.event.ChangeListener listener)
          Removes a listener.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a previously registered listener.
 void removeStateListener(StateListener l)
          Removes a listener.
 void run()
          Most of the real work goes here.
 void setTargetState(int state)
          Sets the desired target state.
 void start()
          Initiates the following asynchronous state transitions: unrealized -> realizing -> realized -> prefetching -> prefetched -> started realizing -> realized -> prefetching -> prefetched -> started realized -> prefetching -> prefetched -> started prefetching -> prefetched -> started prefetched -> started started closed -> throws IllegalStateException
 void stop()
          Initiates the following asynchronous state transitions: started -> prefetched unrealized realizing prefetching prefetched closed -> throws IllegalStateException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ch.randelshofer.media.Player
getCachingModel, getControlPanelComponent, getTimeModel, getTotalDuration, getVisualComponent, isAudioAvailable, isAudioEnabled, isCached, setAudioEnabled
 

Field Detail

listenerList

protected javax.swing.event.EventListenerList listenerList
Listener support.


propertyChangeSupport

protected java.beans.PropertyChangeSupport propertyChangeSupport
Support for property change listeners.


dispatcher

protected SequentialDispatcher dispatcher
The dispatcher.

Constructor Detail

AbstractPlayer

public AbstractPlayer()
Creates a new instance.

Method Detail

getState

public int getState()
Gets the current state of the player.

Specified by:
getState in interface Player
Specified by:
getState in interface StateModel

getTargetState

public int getTargetState()
Gets the target state.

Specified by:
getTargetState in interface Player

setTargetState

public void setTargetState(int state)
Sets the desired target state.

Specified by:
setTargetState in interface Player

realize

public void realize()
Initiates the following asynchronous state transitions: unrealized -> realizing -> realized realizing -> realized realized started -> throws IllegalStateException closed -> throws IllegalStateException

Specified by:
realize in interface Player

prefetch

public void prefetch()
Initiates the following asynchronous state transitions: unrealized -> realizing -> realized -> prefetching -> prefetched realizing -> realized -> prefetching -> prefetched realized -> prefetching -> prefetched prefetching -> prefetched prefetched started -> throws IllegalStateException closed -> throws IllegalStateException

Specified by:
prefetch in interface Player

deallocate

public void deallocate()
Initiates the following asynchronous state transitions: realizing -> unrealized prefetching -> realized prefetched -> realized realized started -> throws IllegalStateException closed -> throws IllegalStateException

Specified by:
deallocate in interface Player

start

public void start()
Initiates the following asynchronous state transitions: unrealized -> realizing -> realized -> prefetching -> prefetched -> started realizing -> realized -> prefetching -> prefetched -> started realized -> prefetching -> prefetched -> started prefetching -> prefetched -> started prefetched -> started started closed -> throws IllegalStateException

Specified by:
start in interface Player

stop

public void stop()
Initiates the following asynchronous state transitions: started -> prefetched unrealized realizing prefetching prefetched closed -> throws IllegalStateException

Specified by:
stop in interface Player

close

public void close()
Initiates the following asynchronous state transitions: any state -> closed

Specified by:
close in interface Player

addStateListener

public void addStateListener(StateListener l)
Adds a listener that wants to be notified about state changes of the player.

Specified by:
addStateListener in interface Player
Specified by:
addStateListener in interface StateModel

removeStateListener

public void removeStateListener(StateListener l)
Removes a listener.

Specified by:
removeStateListener in interface Player
Specified by:
removeStateListener in interface StateModel

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener who is interested in changes of this object.

Specified by:
addPropertyChangeListener in interface Player

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a previously registered listener.

Specified by:
removePropertyChangeListener in interface Player

fireStateChanged

protected void fireStateChanged(int newState)
Notifies all registered state listeners and all registered change listeners.


run

public void run()
Most of the real work goes here. We have to decide when to post events like EndOfMediaEvent and StopAtTimeEvent and TimeLineEvent.

Specified by:
run in interface java.lang.Runnable

doClosed

protected abstract void doClosed()
Does the work for the closed state.


doUnrealized

protected abstract void doUnrealized()
Does the work for the unrealized state.


doRealizing

protected abstract void doRealizing()
Does the work for the realizing state.


doRealized

protected abstract void doRealized()
Does the work for the realized state.


doPrefetching

protected abstract void doPrefetching()
Does the work for the prefetching state.


doPrefetched

protected abstract void doPrefetched()
Does the work for the prefetched state.


doStarted

protected abstract void doStarted()
Does the work for the started state.


addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener listener)
Adds a listener that wants to be notified about state changes of the player.

Specified by:
addChangeListener in interface Player

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener listener)
Removes a listener.

Specified by:
removeChangeListener in interface Player

isActive

public boolean isActive()
Returns true when the target state of the player is equal to STARTED.

Specified by:
isActive in interface Player

Copyright 2011-01-06 Werner Randelshofer