amip.api.highlevel
Class Client

java.lang.Object
  extended by amip.api.highlevel.Client

public class Client
extends java.lang.Object

This class provides access to AMIP itself and also Playlist and Player objects. You must init it before any other communication with AMIP using the init method.


Method Summary
 java.lang.String evaluate(java.lang.String variable)
          Evaluates AMIP variable and returns the result of evaluation as string.
 void execute(java.lang.String command)
          Executes AMIP API command.
 java.lang.String format(int preset)
          Same as format(String spec), but uses AMIP preset with the specified number and formats the result according to this preset.
 java.lang.String format(java.lang.String spec)
          Formats the string with AMIP variables or functions.
 Config getConfig()
           
 int getDcount()
           
 int getDsec()
           
 java.lang.String getHost()
           
static Client getInstance()
          Use this method to get the Client object.
 Player getPlayer()
          Returns Player instance to control your player.
 Playlist getPlaylist()
          Provides access to the Playlist object for operations with player's playlist.
 int getPort()
           
 int getTimeout()
           
 void init()
          You may use this method if AMIP is installed on the same machine and is running on the default port (60333).
 void init(java.lang.String host, int port)
          Simpe init method, uses defaults for timeout (5000), dsec (5) and dcount (1) parameters.
 void init(java.lang.String host, int port, int timeout, int dsec, int dcount)
          Initializes client.
 boolean isInitialized()
           
 boolean pingServer()
          Pings AMIP plugin, useful to know if it's running or not.
 void setDcount(int dcount)
           
 void setDsec(int dsec)
           
 void setHost(java.lang.String host)
           
 void setPort(int port)
           
 void setTimeout(int timeout)
           
 void uninit()
          Uninit client before your application is terminated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Client getInstance()
Use this method to get the Client object.

Returns:
Client instance.

init

public void init(java.lang.String host,
                 int port,
                 int timeout,
                 int dsec,
                 int dcount)
          throws ClientInitializationFailedException
Initializes client.

Parameters:
host - specifies the IP address of the machine where AMIP plugin is installed and running, may be 127.0.0.1 in case AMIP is on the same machine.
port - AMIP plugin port, default is 60333.
timeout - timeout in milliseconds for all the operations, on localhost 1000-5000 is a good option, on slow and unstable connections you may want to use higher values.
dsec - amount of seconds to block any connections for if previous dcount attempts failed.
dcount - threshold of failed operations, if reached, all further connections will be suspended for dsec seconds. dsec and dcount arguments are to prevent lockups in case AMIP can't be reached.
Throws:
ClientInitializationFailedException - if client cannot be initialized with the specified parameters.

init

public void init(java.lang.String host,
                 int port)
          throws ClientInitializationFailedException
Simpe init method, uses defaults for timeout (5000), dsec (5) and dcount (1) parameters.

Parameters:
host - AMIP host.
port - AMIP port.
Throws:
ClientInitializationFailedException

init

public void init()
          throws ClientInitializationFailedException
You may use this method if AMIP is installed on the same machine and is running on the default port (60333). This method initializes client for the 127.0.0.1:60333.

Throws:
ClientInitializationFailedException

uninit

public void uninit()
Uninit client before your application is terminated.


evaluate

public java.lang.String evaluate(java.lang.String variable)
                          throws GeneralClientException
Evaluates AMIP variable and returns the result of evaluation as string.

Parameters:
variable - AMIP API command/variable to evaluate, for example 'var_name' or 'cfg_enabled'.
Returns:
the result of evaluation.
Throws:
GeneralClientException

execute

public void execute(java.lang.String command)
             throws GeneralClientException
Executes AMIP API command.

Parameters:
command - API command, such as 'control pause'.
Throws:
GeneralClientException

format

public java.lang.String format(java.lang.String spec)
                        throws GeneralClientException
Formats the string with AMIP variables or functions.

Parameters:
spec - the string which may contain AMIP variables and functions, for example "$cf(%1 - %2)".
Returns:
result the string with information provided by AMIP and formatted according to spec.
Throws:
GeneralClientException

format

public java.lang.String format(int preset)
                        throws GeneralClientException
Same as format(String spec), but uses AMIP preset with the specified number and formats the result according to this preset.

Parameters:
preset - AMIP preset to format song info according to (can take value from 1 to 5).
Returns:
the string with information provided by AMIP and formatted according to specified preset.
Throws:
GeneralClientException

pingServer

public boolean pingServer()
Pings AMIP plugin, useful to know if it's running or not. Note that it returns false if player with installed AMIP is not running on the host:port client was initialized for or in case AMIP Server/API is disabled.

Returns:
true if AMIP is running on the specified port and host, false otherwise.

getDcount

public int getDcount()

setDcount

public void setDcount(int dcount)

getDsec

public int getDsec()

setDsec

public void setDsec(int dsec)

getTimeout

public int getTimeout()

setTimeout

public void setTimeout(int timeout)

getPort

public int getPort()

setPort

public void setPort(int port)

getHost

public java.lang.String getHost()

setHost

public void setHost(java.lang.String host)

isInitialized

public boolean isInitialized()

getPlaylist

public Playlist getPlaylist()
Provides access to the Playlist object for operations with player's playlist.

Returns:
Playlist instance.

getPlayer

public Player getPlayer()
Returns Player instance to control your player.

Returns:
Player instance.

getConfig

public Config getConfig()