net.sourceforge.atunes.kernel.handlers
Class PlayerHandler

java.lang.Object
  extended by net.sourceforge.atunes.kernel.handlers.PlayerHandler
All Implemented Interfaces:
ApplicationFinishListener
Direct Known Subclasses:
MPlayerHandler, XineHandler

public abstract class PlayerHandler
extends java.lang.Object
implements ApplicationFinishListener

The Class PlayerHandler. This class has common logic for all player engines


Field Summary
static java.lang.String DEFAULT_ENGINE
          Default player engine
protected static Logger logger
          The logger used in player engines
 
Constructor Summary
protected PlayerHandler()
          Instantiates a new player handler.
 
Method Summary
 void applicationFinish()
          Called when application finishes
protected abstract  void applyEqualization(float[] values)
          This method must be implemented by player engines.
abstract  void applyMuteState(boolean state)
          This method must be implemented by player engines.
protected abstract  void finishPlayer()
          This method must be implemented by player engines It's called when application finishes
 java.lang.String[] getEngineNames()
          Return list of engine names as configured in settings file This method is mainly designed to be used in preferences window to select a player engine by its name
protected  float[] getEqualizerValues()
          Returns equalizer values or null if equalizer is disabled TODO: Add more explanation about equalizer values
static PlayerHandler getInstance()
          Gets the single instance of PlayerHandler.
protected abstract  boolean isEngineAvailable()
          This method must be implemented by player engines.
abstract  boolean isEnginePlaying()
          Checks if engine is currently playing (true) or not ( false)
protected  boolean isMuteEnabled()
          Checks if mute is enabled (true) or not (false)
protected  boolean isPaused()
          Checks if playback is paused.
protected  boolean isSoundNormalizationEnabled()
          Checks if sound normalization is enabled (true) or not ( false)
static void notifyPlayerError(java.lang.Exception e)
          Called when a exception is thrown related with player engine
protected  void notifyRadioOrPodcastFeedEntryStarted()
          Notifies the handler that the radio or podcast feed entry has started playing (MPlayer bug workaround).
protected abstract  void pausePlayback()
          This method must be implemented by player engines.
 void playCurrentAudioObject(boolean buttonPressed)
          Starts playing current audio object from play list
 void playNextAudioObject(boolean autoNext)
          Starts playing next audio object from play list
 void playPreviousAudioObject()
          Starts playing previous audio object from play list
protected abstract  void resumePlayback()
          This method must be implemented by player engines.
 void seekCurrentAudioObject(double position)
          Seek function: play current audio object from position defined by parameter (0-100%)
protected abstract  void seekTo(double perCent)
          This method must be implemented by player engines.
protected  void setCurrentAudioObjectLength(long currentLength)
          Sets the length of the current audio object
protected  void setCurrentAudioObjectPlayedTime(long playedTime)
          Sets the time played for the current audio object as playback advances
 void setPlayListPositionToPlay(int pos)
          Sets position to play in current play list
abstract  void setVolume(int perCent)
          This method must be implemented by player engines.
protected abstract  void startPlayback(AudioObject audioObjectToPlay, AudioObject audioObject)
          play this audio object
 void stopCurrentAudioObject(boolean userStopped)
          Stops playing current audio object
protected abstract  void stopPlayback(boolean userStopped, boolean useFadeAway)
          This method must be implemented by player engines.
abstract  boolean supportsCapability(PlayerEngineCapability capability)
          This method must be implemented by player engines.
protected abstract  float[] transformEqualizerValues(float[] values)
          This method must be implemented by player engines.
 void volumeDown()
          Lower volume
 void volumeUp()
          Raise volume
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static Logger logger
The logger used in player engines


DEFAULT_ENGINE

public static final java.lang.String DEFAULT_ENGINE
Default player engine

See Also:
Constant Field Values
Constructor Detail

PlayerHandler

protected PlayerHandler()
Instantiates a new player handler.

Method Detail

isEnginePlaying

public abstract boolean isEnginePlaying()
Checks if engine is currently playing (true) or not ( false)

Returns:
true if engine is currently playing

isEngineAvailable

protected abstract boolean isEngineAvailable()
This method must be implemented by player engines. This method must check system to determine if player engine is available (check for libraries or commands)

Returns:
true if engine is available in the system and can be used to play, false otherwise

startPlayback

protected abstract void startPlayback(AudioObject audioObjectToPlay,
                                      AudioObject audioObject)
play this audio object

Parameters:
audioObjectToPlay - audio object to play. May be cashed to temp dirs or the same as audioObject.
audioObject - original audio object to update statistics TODO: Change method signature and add javadoc

pausePlayback

protected abstract void pausePlayback()
This method must be implemented by player engines. This method pauses playback of current audio object without stopping it. Resuming after this called should continue playback from the position when paused


resumePlayback

protected abstract void resumePlayback()
This method must be implemented by player engines. This method resumes playback of current audio object previously paused. Call this method should continue playback from the position when paused


stopPlayback

protected abstract void stopPlayback(boolean userStopped,
                                     boolean useFadeAway)
This method must be implemented by player engines. Stop playing current song

Parameters:
userStopped - true if stopped by user input, false otherwise.
useFadeAway - if true - fade away then stop. Stop immediately otherwise.

seekTo

protected abstract void seekTo(double perCent)
This method must be implemented by player engines. Applies a seek operation in player engine

Parameters:
perCent - 0-100

setVolume

public abstract void setVolume(int perCent)
This method must be implemented by player engines. Applies volume value in player engine

Parameters:
perCent - 0-100

applyMuteState

public abstract void applyMuteState(boolean state)
This method must be implemented by player engines. Apply mute state in player engine

Parameters:
state - : enabled (true) or disabled (false)

supportsCapability

public abstract boolean supportsCapability(PlayerEngineCapability capability)
This method must be implemented by player engines. Returns if engine supports capability or not

Returns:
true if engine supports capability or not

applyEqualization

protected abstract void applyEqualization(float[] values)
This method must be implemented by player engines. Method to apply equalizer values in player engine

Parameters:
values -

transformEqualizerValues

protected abstract float[] transformEqualizerValues(float[] values)
This method must be implemented by player engines. Transform values retrieved from equalizer dialog to values for player engine

Parameters:
values -
Returns:

finishPlayer

protected abstract void finishPlayer()
This method must be implemented by player engines It's called when application finishes


getInstance

public static final PlayerHandler getInstance()
Gets the single instance of PlayerHandler. This method returns player engine configured by user or default if it's available on the system

Returns:
single instance of PlayerHandler

getEngineNames

public final java.lang.String[] getEngineNames()
Return list of engine names as configured in settings file This method is mainly designed to be used in preferences window to select a player engine by its name

Returns:

playCurrentAudioObject

public final void playCurrentAudioObject(boolean buttonPressed)
Starts playing current audio object from play list

Parameters:
buttonPressed - TODO: Add more javadoc

stopCurrentAudioObject

public final void stopCurrentAudioObject(boolean userStopped)
Stops playing current audio object

Parameters:
userStopped - true if user has stopped playback

playPreviousAudioObject

public final void playPreviousAudioObject()
Starts playing previous audio object from play list


playNextAudioObject

public final void playNextAudioObject(boolean autoNext)
Starts playing next audio object from play list

Parameters:
autoNext - true if this method is called because current audio object has finished, false if this method is called because user has pressed the "NEXT" button

seekCurrentAudioObject

public final void seekCurrentAudioObject(double position)
Seek function: play current audio object from position defined by parameter (0-100%)

Parameters:
position - From start of audio object (0) to end of audio object (100)

setPlayListPositionToPlay

public final void setPlayListPositionToPlay(int pos)
Sets position to play in current play list

Parameters:
pos - the new play list position to play

volumeDown

public final void volumeDown()
Lower volume


volumeUp

public final void volumeUp()
Raise volume


notifyPlayerError

public static final void notifyPlayerError(java.lang.Exception e)
Called when a exception is thrown related with player engine

Parameters:
e - The exception thrown

applicationFinish

public void applicationFinish()
Description copied from interface: ApplicationFinishListener
Called when application finishes

Specified by:
applicationFinish in interface ApplicationFinishListener

getEqualizerValues

protected final float[] getEqualizerValues()
Returns equalizer values or null if equalizer is disabled TODO: Add more explanation about equalizer values

Returns:
the equalizer

isSoundNormalizationEnabled

protected final boolean isSoundNormalizationEnabled()
Checks if sound normalization is enabled (true) or not ( false)

Returns:
true if sound normalization is enabled

isMuteEnabled

protected final boolean isMuteEnabled()
Checks if mute is enabled (true) or not (false)

Returns:
true if mute is enabled

setCurrentAudioObjectLength

protected final void setCurrentAudioObjectLength(long currentLength)
Sets the length of the current audio object

Parameters:
currentLength - The length of the current audio object in milliseconds (ms)

setCurrentAudioObjectPlayedTime

protected final void setCurrentAudioObjectPlayedTime(long playedTime)
Sets the time played for the current audio object as playback advances

Parameters:
playedTime - played time in milliseconds (ms)

isPaused

protected final boolean isPaused()
Checks if playback is paused.

Returns:
true, if is paused

notifyRadioOrPodcastFeedEntryStarted

protected final void notifyRadioOrPodcastFeedEntryStarted()
Notifies the handler that the radio or podcast feed entry has started playing (MPlayer bug workaround).



Copyright © 2006-2008 The aTunes Team. All Rights Reserved.