org.bff.javampd
Class MPD

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

public class MPD
extends java.lang.Object

MPD represents a connection to a MPD server. The commands are maintained in a properties file called mpd.properties.


Field Summary
protected static java.lang.String SONGPREFIXALBUM
          the MPD prefix for the album
protected static java.lang.String SONGPREFIXARTIST
          the MPD prefix for the artist
protected static java.lang.String SONGPREFIXDATE
          the MPD prefix for the title
protected static java.lang.String SONGPREFIXFILE
          the MPD prefix for the filename
protected static java.lang.String SONGPREFIXGENRE
          the MPD prefix for the title
protected static java.lang.String SONGPREFIXID
          the MPD prefix for the song id
protected static java.lang.String SONGPREFIXPOS
          the MPD prefix for the playlist position
protected static java.lang.String SONGPREFIXTIME
          the MPD prefix for the time
protected static java.lang.String SONGPREFIXTITLE
          the MPD prefix for the title
protected static java.lang.String SONGPREFIXTRACK
          the MPD prefix for the track number
protected static java.lang.String STATUS_PAUSED
          status of paused
protected static java.lang.String STATUS_PLAYING
          status of playing
protected static java.lang.String STATUS_STOPPED
          status of stopped
 
Constructor Summary
MPD(java.lang.String server)
          Creates a new instance of MPD without authentication using the default MPD port of 6600
MPD(java.lang.String server, int port)
          Creates a new instance of MPD without authentication
MPD(java.lang.String server, int port, java.lang.String password)
          Creates a new instance of MPD with authentication.
 
Method Summary
 void clearerror()
          Clears the current error message in the MPD status
 void close()
          Closes the connection to the MPD server.
protected  java.util.Collection<MPDSong> convertResponseToSong(java.util.List<java.lang.String> list)
          Converts the response from the MPD server into a MPDSong object.
protected  java.lang.String getLastError()
          Returns the last error generated by isResponseOK.
 MPDAdmin getMPDAdmin()
          Returns a MPDAdmin using this class as the connection for the administrator.
 MPDDatabase getMPDDatabase()
          Returns a MPDDatabase using this class as the connection for the database.
 MPDEventRelayer getMPDEventRelayer()
          Returns a MPDEventRelayer using this class as the connection.
 MPDPlayer getMPDPlayer()
          Returns a MPDPlayer using this class as the connection for the player.
 MPDPlaylist getMPDPlaylist()
          Returns a MPDPlaylist using this class as the connection for the playlist.
 long getPlaytime()
          Returns the time length of the music played since the server was started.
protected  java.lang.String getServerStat(org.bff.javampd.MPD.StatList stat)
          Returns the statistics of the requested statistics element.
 java.util.Collection<java.lang.String> getStatus()
          Returns the full status of the MPD server as a Collection of Strings.
protected  java.lang.String getStatus(org.bff.javampd.MPD.StatusList status)
          Returns the current status of the requested status element.
 long getUptime()
          Returns the MPD server daemon uptime in seconds.
 java.lang.String getVersion()
          Returns the MPD version running on the server.
 boolean isConnected()
          Determines if there is a connection to the MPD server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SONGPREFIXFILE

protected static final java.lang.String SONGPREFIXFILE
the MPD prefix for the filename

See Also:
Constant Field Values

SONGPREFIXARTIST

protected static final java.lang.String SONGPREFIXARTIST
the MPD prefix for the artist

See Also:
Constant Field Values

SONGPREFIXALBUM

protected static final java.lang.String SONGPREFIXALBUM
the MPD prefix for the album

See Also:
Constant Field Values

SONGPREFIXTRACK

protected static final java.lang.String SONGPREFIXTRACK
the MPD prefix for the track number

See Also:
Constant Field Values

SONGPREFIXTITLE

protected static final java.lang.String SONGPREFIXTITLE
the MPD prefix for the title

See Also:
Constant Field Values

SONGPREFIXDATE

protected static final java.lang.String SONGPREFIXDATE
the MPD prefix for the title

See Also:
Constant Field Values

SONGPREFIXGENRE

protected static final java.lang.String SONGPREFIXGENRE
the MPD prefix for the title

See Also:
Constant Field Values

SONGPREFIXTIME

protected static final java.lang.String SONGPREFIXTIME
the MPD prefix for the time

See Also:
Constant Field Values

SONGPREFIXPOS

protected static final java.lang.String SONGPREFIXPOS
the MPD prefix for the playlist position

See Also:
Constant Field Values

SONGPREFIXID

protected static final java.lang.String SONGPREFIXID
the MPD prefix for the song id

See Also:
Constant Field Values

STATUS_PLAYING

protected static final java.lang.String STATUS_PLAYING
status of playing

See Also:
Constant Field Values

STATUS_PAUSED

protected static final java.lang.String STATUS_PAUSED
status of paused

See Also:
Constant Field Values

STATUS_STOPPED

protected static final java.lang.String STATUS_STOPPED
status of stopped

See Also:
Constant Field Values
Constructor Detail

MPD

public MPD(java.lang.String server)
    throws java.net.UnknownHostException,
           MPDConnectionException
Creates a new instance of MPD without authentication using the default MPD port of 6600

Parameters:
server - the MPD Server
Throws:
MPDConnectionException - if there is a problem sending the command to the server
java.net.UnknownHostException - If the host name used for the server is unknown to dns

MPD

public MPD(java.lang.String server,
           int port)
    throws java.net.UnknownHostException,
           MPDConnectionException
Creates a new instance of MPD without authentication

Parameters:
server - the MPD Server
port - the port MPD is listening on
Throws:
MPDConnectionException - if there is a problem sending the command to the server
java.net.UnknownHostException - If the host name used for the server is unknown to dns

MPD

public MPD(java.lang.String server,
           int port,
           java.lang.String password)
    throws java.net.UnknownHostException,
           MPDConnectionException
Creates a new instance of MPD with authentication. The password is used to gain access to the commands setup by the MPD administrator. Please note the password is sent plain text.

Parameters:
server - the MPD server
port - the port MPD is listening on
password - the password to authenticate with
Throws:
MPDConnectionException - if there is a problem sending the command to the server
java.net.UnknownHostException - If the host name used for the server is unknown to dns
Method Detail

clearerror

public void clearerror()
                throws MPDConnectionException,
                       MPDResponseException
Clears the current error message in the MPD status

Throws:
MPDResponseException - if the MPD response generates an error
MPDConnectionException - if there is a problem sending the command to the server

close

public void close()
           throws MPDConnectionException,
                  MPDResponseException
Closes the connection to the MPD server.

Throws:
MPDResponseException - if the MPD response generates an error
MPDConnectionException - if there is a problem sending the command to the server

getPlaytime

public long getPlaytime()
                 throws MPDConnectionException,
                        MPDResponseException
Returns the time length of the music played since the server was started.

Returns:
the time length of the music played
Throws:
MPDResponseException - if the MPD response generates an error
MPDConnectionException - if there is a problem sending the command to the server

getUptime

public long getUptime()
               throws MPDConnectionException,
                      MPDResponseException
Returns the MPD server daemon uptime in seconds.

Returns:
the server uptime in seconds
Throws:
MPDResponseException - if the MPD response generates an error
MPDConnectionException - if there is a problem sending the command to the server

getVersion

public java.lang.String getVersion()
Returns the MPD version running on the server.

Returns:
the version of the MPD

getMPDPlayer

public MPDPlayer getMPDPlayer()
Returns a MPDPlayer using this class as the connection for the player. Multiple calls to this method will return the same MPDPlayer class.

Returns:
the mpd player

getMPDPlaylist

public MPDPlaylist getMPDPlaylist()
Returns a MPDPlaylist using this class as the connection for the playlist. Multiple calls to this method will return the same MPDPlaylist class.

Returns:
the mpd player

getMPDDatabase

public MPDDatabase getMPDDatabase()
Returns a MPDDatabase using this class as the connection for the database. Multiple calls to this method will return the same MPDDatabase class.

Returns:
the mpd player

getMPDAdmin

public MPDAdmin getMPDAdmin()
Returns a MPDAdmin using this class as the connection for the administrator. Multiple calls to this method will return the same MPDAdmin class.

Returns:
the mpd player

getMPDEventRelayer

public MPDEventRelayer getMPDEventRelayer()
Returns a MPDEventRelayer using this class as the connection. Multiple calls to this method will return the same MPDEventRelayer class.

Returns:
the MPDEventRelayer

isConnected

public boolean isConnected()
Determines if there is a connection to the MPD server.

Returns:
true if connected to server , false if not

getStatus

public java.util.Collection<java.lang.String> getStatus()
                                                 throws MPDConnectionException,
                                                        MPDResponseException
Returns the full status of the MPD server as a Collection of Strings. To query specific statuses use getStatus(StatusList status).

Returns:
the desired status information
Throws:
MPDResponseException - if the MPD response generates an error
MPDConnectionException - if there is a problem sending the command to the server

getStatus

protected java.lang.String getStatus(org.bff.javampd.MPD.StatusList status)
                              throws MPDConnectionException,
                                     MPDResponseException
Returns the current status of the requested status element. See StatusList for a list of possible items returned by getStatus.

Parameters:
status - the status desired
Returns:
the desired status information
Throws:
MPDResponseException - if the MPD response generates an error
MPDConnectionException - if there is a problem sending the command to the server

getServerStat

protected java.lang.String getServerStat(org.bff.javampd.MPD.StatList stat)
                                  throws MPDConnectionException,
                                         MPDResponseException
Returns the statistics of the requested statistics element. See StatList for a list of possible items returned by getServerStat.

Parameters:
stat - the statistic desired
Returns:
the requested statistic
Throws:
MPDResponseException - if the MPD response generates an error
MPDConnectionException - if there is a problem sending the command to the server

convertResponseToSong

protected java.util.Collection<MPDSong> convertResponseToSong(java.util.List<java.lang.String> list)
Converts the response from the MPD server into a MPDSong object.

Parameters:
list - the response from the MPD server
Returns:
a MPDSong object

getLastError

protected java.lang.String getLastError()
Returns the last error generated by isResponseOK.

Returns:
the error message