org.bff.javampd
Class MPDPlaylist

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

public class MPDPlaylist
extends java.lang.Object

MPDPlaylist represents a playlist controller to a MPD server. To obtain an instance of the class you must use the getMPDPlaylist 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.


Method Summary
 void addDirectory(java.lang.String dir)
          Adds a directory of songs to the playlist.
 void addPlaylistChangeListener(PlaylistChangeListener pcl)
          Adds a PlaylistChangeListener to this object to receive PlaylistChangeEvents.
 boolean addSong(MPDSong song)
          Adds a MPDSong to the playlist.
 boolean addSongs(java.util.List<MPDSong> songList)
          Adds a List of MPDSongs to the playlist.
 boolean clearPlaylist()
          Removes all songs from the playlist.
 void deletePlaylist(java.lang.String playlistName)
          Deletes the playlist from the MPD server.
protected  void firePlaylistChangeEvent(int id)
          Sends the appropriate PlaylistChangeEvent to all registered PlaylistChangeListener.
 MPDSong getCurrentSong()
          Returns the current song.
 java.util.List<MPDSong> getSongList()
          Returns the list of songs in the playlist.
 int getVersion()
          Returns the playlist version.
 void loadPlaylist(java.lang.String playlistName)
          Loads the songs in the given playlist to the current playlist.
 void move(MPDSong song, int to)
          Moves the desired song to the given position in the playlist.
 void removePlaylistStatusChangedListener(PlaylistChangeListener pcl)
          Removes a PlaylistChangeListener from this object.
 boolean removeSong(MPDSong song)
          Removes a MPDSong from the playlist.
 boolean savePlaylist(java.lang.String playlistName)
          Saves the current playlist as the passed playlist name.
 void shuffle()
          Shuffles the songs in the playlist.
 void swap(MPDSong song1, MPDSong song2)
          Swaps the given two songs in the playlist.
 java.lang.String toString()
          Returns the string representation of this playlist.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

addPlaylistChangeListener

public void addPlaylistChangeListener(PlaylistChangeListener pcl)
Adds a PlaylistChangeListener to this object to receive PlaylistChangeEvents.

Parameters:
pcl - the PlaylistChangeListener to add

removePlaylistStatusChangedListener

public void removePlaylistStatusChangedListener(PlaylistChangeListener pcl)
Removes a PlaylistChangeListener from this object.

Parameters:
pcl - the PlaylistChangeListener to remove

firePlaylistChangeEvent

protected void firePlaylistChangeEvent(int id)
Sends the appropriate PlaylistChangeEvent to all registered PlaylistChangeListener.

Parameters:
id - the event id to send

loadPlaylist

public void loadPlaylist(java.lang.String playlistName)
                  throws MPDConnectionException,
                         MPDPlaylistException
Loads the songs in the given playlist to the current playlist. The playlist name can be givin with or without the .m3u extension.

Parameters:
playlistName - the playlist name
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

addSong

public boolean addSong(MPDSong song)
                throws MPDConnectionException,
                       MPDPlaylistException
Adds a MPDSong to the playlist.

Parameters:
song - the song to add
Returns:
true if the song was added, false otherwise
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

addSongs

public boolean addSongs(java.util.List<MPDSong> songList)
                 throws MPDConnectionException,
                        MPDPlaylistException
Adds a List of MPDSongs to the playlist.

Parameters:
songList - the list of songs to add
Returns:
true if the songs are added successfully; false otherwise
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

addDirectory

public void addDirectory(java.lang.String dir)
                  throws MPDConnectionException,
                         MPDPlaylistException
Adds a directory of songs to the playlist.

Parameters:
dir - the directory to add
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

removeSong

public boolean removeSong(MPDSong song)
                   throws MPDConnectionException,
                          MPDPlaylistException
Removes a MPDSong from the playlist.

Parameters:
song - the song to remove
Returns:
true if the song is removed; false otherwise
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

getCurrentSong

public MPDSong getCurrentSong()
                       throws MPDConnectionException,
                              MPDPlaylistException
Returns the current song.

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

clearPlaylist

public boolean clearPlaylist()
                      throws MPDConnectionException,
                             MPDPlaylistException
Removes all songs from the playlist.

Returns:
true if the playlist was cleared
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

deletePlaylist

public void deletePlaylist(java.lang.String playlistName)
                    throws MPDConnectionException,
                           MPDPlaylistException
Deletes the playlist from the MPD server.

Parameters:
playlistName - the playlist to delete
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

move

public void move(MPDSong song,
                 int to)
          throws MPDConnectionException,
                 MPDPlaylistException
Moves the desired song to the given position in the playlist.

Parameters:
song - the song to move
to - the position to move the song to
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

shuffle

public void shuffle()
             throws MPDConnectionException,
                    MPDPlaylistException
Shuffles the songs in the playlist.

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

swap

public void swap(MPDSong song1,
                 MPDSong song2)
          throws MPDConnectionException,
                 MPDPlaylistException
Swaps the given two songs in the playlist.

Parameters:
song1 - first song to swap
song2 - second song to swap
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

savePlaylist

public boolean savePlaylist(java.lang.String playlistName)
                     throws MPDConnectionException,
                            MPDPlaylistException
Saves the current playlist as the passed playlist name.

Parameters:
playlistName - the playlist name for the playlist
Returns:
true if the playlist is saved; otherwise false
Throws:
MPDPlaylistException - if the MPD responded with an error
MPDConnectionException - if there is a problem sending the command

getVersion

public int getVersion()
Returns the playlist version.

Returns:
the playlist version

getSongList

public java.util.List<MPDSong> getSongList()
Returns the list of songs in the playlist.

Returns:
the song list

toString

public java.lang.String toString()
Returns the string representation of this playlist.

Overrides:
toString in class java.lang.Object
Returns:
the string representation