Class AbstractPlayer

java.lang.Object
org.monte.media.player.AbstractPlayer
All Implemented Interfaces:
Runnable, Player, StateModel

public abstract class AbstractPlayer extends Object implements Player, Runnable
Generic interface for media players.
Author:
Werner Randelshofer, Hausmatt 10, CH-6405 Goldau, Switzerland
  • Field Details

  • Constructor Details

    • AbstractPlayer

      public AbstractPlayer()
      Creates a new instance.
  • Method Details

    • 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(PropertyChangeListener listener)
      Adds a listener who is interested in changes of this object.
      Specified by:
      addPropertyChangeListener in interface Player
    • removePropertyChangeListener

      public void removePropertyChangeListener(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.
    • fireStateChanged

      protected void fireStateChanged()
      Notifies 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 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(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(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