org.bff.javampd
Class MPDPlayer

java.lang.Object
  extended by org.bff.javampd.MPDPlayer

public class MPDPlayer
extends java.lang.Object

MPDPlayer represents a player controller to a MPD server. To obtain an instance of the class you must use the getMPDPlayer method from the MPD connection class. This class does not have a public constructor (singleton model) so the object must be obtained from the connection object.


Nested Class Summary
static class MPDPlayer.PlayerStatus
          The status of the player.
 
Method Summary
 void addPlayerChangeListener(PlayerChangeListener pcl)
          Adds a PlayerChangeListener to this object to receive PlayerChangeEvents.
 void addVolumeChangeListener(VolumeChangeListener vcl)
          Adds a VolumeChangeListener to this object to receive VolumeChangeEvents.
protected  void firePlayerChangeEvent(int id)
          Sends the appropriate PlayerChangeEvent to all registered PlayerChangeListeners.
protected  void fireVolumeChangeEvent(int volume)
          Sends the appropriate VolumeChangeEvent to all registered VolumeChangeListener.
 int getBitrate()
          Returns the instantaneous bitrate of the currently playing song.
 MPDSong getCurrentSong()
          Returns the current song either playing or queued for playing.
 long getElapsedTime()
          Returns the elapsed time of the current song in seconds.
 MPDPlayer.PlayerStatus getStatus()
          Returns the current status of the player.
 int getVolume()
          Returns the current volume of the player.
 int getXFade()
          Returns the cross fade of the player in seconds.
 boolean isRepeat()
          Returns if the player is repeating.
 void mute()
          Mutes the volume of the player.
 void pause()
          Pauses the player.
 void play()
          Starts the player.
 void playId(MPDSong song)
          Starts the player with the specified song.
 void playNext()
          Plays the next song in the playlist.
 void playPrev()
          Plays the previous song in the playlist.
 void removePlayerChangedListener(PlayerChangeListener pcl)
          Removes a PlayerChangeListener from this object.
 void removeVolumeChangedListener(VolumeChangeListener vcl)
          Removes a VolumeChangeListener from this object.
 void seek(long secs)
          Seeks to the desired location in the current song.
 void seekId(MPDSong song, long secs)
          Seeks to the desired location in the specified song.
 void setRepeat(boolean shouldRepeat)
          Sets the repeating status of the player.
 void setVolume(int volume)
          Sets the volume of the player.
 void setXFade(int xFade)
          Sets the cross fade of the player in seconds.
 void stop()
          Stops the player.
 void unMute()
          Unmutes the volume of the player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCurrentSong

public MPDSong getCurrentSong()
                       throws MPDConnectionException,
                              MPDPlayerException
Returns the current song either playing or queued for playing.

Returns:
the current song
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

addPlayerChangeListener

public void addPlayerChangeListener(PlayerChangeListener pcl)
Adds a PlayerChangeListener to this object to receive PlayerChangeEvents.

Parameters:
pcl - the PlayerChangeListener to add

removePlayerChangedListener

public void removePlayerChangedListener(PlayerChangeListener pcl)
Removes a PlayerChangeListener from this object.

Parameters:
pcl - the PlayerChangeListener to remove

firePlayerChangeEvent

protected void firePlayerChangeEvent(int id)
Sends the appropriate PlayerChangeEvent to all registered PlayerChangeListeners.

Parameters:
id - the event id to send

addVolumeChangeListener

public void addVolumeChangeListener(VolumeChangeListener vcl)
Adds a VolumeChangeListener to this object to receive VolumeChangeEvents.

Parameters:
vcl - the VolumeChangeListener to add

removeVolumeChangedListener

public void removeVolumeChangedListener(VolumeChangeListener vcl)
Removes a VolumeChangeListener from this object.

Parameters:
vcl - the VolumeChangeListener to remove

fireVolumeChangeEvent

protected void fireVolumeChangeEvent(int volume)
Sends the appropriate VolumeChangeEvent to all registered VolumeChangeListener.

Parameters:
volume - the new volume

play

public void play()
          throws MPDConnectionException,
                 MPDPlayerException
Starts the player.

Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

playId

public void playId(MPDSong song)
            throws MPDConnectionException,
                   MPDPlayerException
Starts the player with the specified song.

Parameters:
song - the song to start the player with
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

seek

public void seek(long secs)
          throws MPDConnectionException,
                 MPDPlayerException
Seeks to the desired location in the current song. If the location is larger than the length of the song or is less than 0 then the parameter is ignored.

Parameters:
secs - the location to seek to
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

seekId

public void seekId(MPDSong song,
                   long secs)
            throws MPDConnectionException,
                   MPDPlayerException
Seeks to the desired location in the specified song. If the location is larger than the length of the song or is less than 0 then the parameter is ignored.

Parameters:
song - the song to seek in
secs - the location to seek to
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

stop

public void stop()
          throws MPDConnectionException,
                 MPDPlayerException
Stops the player.

Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

pause

public void pause()
           throws MPDConnectionException,
                  MPDPlayerException
Pauses the player.

Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

playNext

public void playNext()
              throws MPDConnectionException,
                     MPDPlayerException
Plays the next song in the playlist.

Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

playPrev

public void playPrev()
              throws MPDConnectionException,
                     MPDPlayerException
Plays the previous song in the playlist.

Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

mute

public void mute()
          throws MPDConnectionException,
                 MPDPlayerException
Mutes the volume of the player.

Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

unMute

public void unMute()
            throws MPDConnectionException,
                   MPDPlayerException
Unmutes the volume of the player.

Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

getBitrate

public int getBitrate()
               throws MPDConnectionException,
                      MPDPlayerException
Returns the instantaneous bitrate of the currently playing song.

Returns:
the instantaneous bitrate in kbps
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

getVolume

public int getVolume()
              throws MPDConnectionException,
                     MPDPlayerException
Returns the current volume of the player.

Returns:
the volume of the player (0-100)
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

setVolume

public void setVolume(int volume)
               throws MPDConnectionException,
                      MPDPlayerException
Sets the volume of the player. The volume is between 0 and 100, any volume less that 0 results in a volume of 0 while any volume greater than 100 results in a volume of 100.

Parameters:
volume - the volume level (0-100)
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

isRepeat

public boolean isRepeat()
                 throws MPDConnectionException,
                        MPDPlayerException
Returns if the player is repeating.

Returns:
is the player repeating
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

setRepeat

public void setRepeat(boolean shouldRepeat)
               throws MPDConnectionException,
                      MPDPlayerException
Sets the repeating status of the player.

Parameters:
shouldRepeat - should the player repeat the current song
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

getXFade

public int getXFade()
             throws MPDConnectionException,
                    MPDPlayerException
Returns the cross fade of the player in seconds.

Returns:
the cross fade of the player in seconds
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

setXFade

public void setXFade(int xFade)
              throws MPDConnectionException,
                     MPDPlayerException
Sets the cross fade of the player in seconds.

Parameters:
xFade - the amount of cross fade to set in seconds
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

getElapsedTime

public long getElapsedTime()
                    throws MPDConnectionException,
                           MPDPlayerException
Returns the elapsed time of the current song in seconds.

Returns:
the elapsed time of the song in seconds
Throws:
MPDPlayerException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

getStatus

public MPDPlayer.PlayerStatus getStatus()
                                 throws MPDException
Returns the current status of the player.

Returns:
the status of the player
Throws:
MPDException