Audio::MPD - Class for talking to MPD (Music Player Daemon) servers use Audio::MPD; my $mpd = Audio::MPD->new(); $mpd->play(); sleep 10; $mpd->next(); Audio::MPD gives a clear object-oriented interface for talking to and controlling MPD (Music Player Daemon) servers. A connection to the MPD server is established as soon as a new Audio::MPD object is created. Commands are then sent to the server as the class's methods are called.

Constructor
The "new()" method is the constructor for the "Audio::MPD" class. You may specify a hostname and port - if none is specified then the enviroment variables "MPD_HOST" and "MPD_PORT" are checked. Finally if all else fails the defaults 'localhost' and '6600' are used. An optional password can be specified by prepending it to the hostname, seperated with an '@' character.

Controlling the server
Check to see if there is a valid connection to the MPD server. First check that the socket is connected and then send a Ping command check that the replyis 'OK'. Return '1' if connected and undef if not. Close the connection to the MPD server. Send a message to the MPD server telling it to shut down. Force mpd to recan its collection. If $path (relative to MPD's music directory) is supplied, MPD will only scan it - otherwise, MPD will rescan its whole collection. Send a plaintext password to the server, which can enable optionally password protected functionality. Return an array of supported URL schemes. Return an array containing information about the last error that occured. - Item 0: The ID number of the error - Item 1: Human readable error message - Item 2: The command that caused the error - Item 3: The position in the command_list of the command (if used) Return the version number for the server we are connected to.

Changing MPD settings
Set the repeat mode to $repeat (1 or 0). If $repeat is not specified then the repeat mode is toggled. Set the random mode to $random (1 or 0). If $random is not specified then the random mode is toggled. Enable crossfading and set the duration of crossfade between songs. If $seconds is not specified or $seconds is 0, then crossfading is disabled. Sets the audio output volume percentage to absolute $volume. If $volume is prefixed by '+' or '-' then the volume is changed relatively by that value. Enable the specified audio output. $output is the ID of the audio output. Disable the specified audio output. $output is the ID of the audio output.

Controlling playback
Begin playing playlist at song number $number. If $fromid is true then begin playing at song with ID $number. Begin playing playlist at song ID $songid. Pause playback. If $state is 0 then the current track is unpaused, if $state is 1 then the current track is paused. Stop playback. Play next song in playlist. Play previous song in playlist. Seek to $position seconds. If $song number is not specified then the perl module will try and seek to $position in the current song. If $fromid is true then $song is the ID of the song to seek in. Seek to $position seconds in song ID $songid.

Playlist handling
Remove all the songs from the current playlist. No return value. Remove all of the songs from the current playlist *except* the song currently playing. Add the song identified by $path (relative to MPD's music directory) to the current playlist. No return value. Remove song number $song from the current playlist. If $fromid is true, then $song is the ID of the song to be removed. No return value. Remove the specified $songid from the current playlist. No return value. Swap positions of song number $song1 and $song2 on the current playlist. If $fromid is true, then $song1 and $song are the IDs of the songs. No return value. Swap the postions of song ID $songid1 with song ID $songid2 on the current playlist. No return value. Shuffle the current playlist. No return value. Move song number $song to the position $newpos. If $fromid is true, then $song is the ID of the song. No return value. Move song ID $songid to the position $newpos. No return value. Load list of songs from specified $playlist file. No return value. Save the current playlist to a file called $playlist in MPD's playlist directory. No return value. Delete playlist named $playlist from MPD's playlist directory. No return value.

Retrieving information from the collection
Search through MPD's database of music for matching songs. $type is the field to search in: "title","artist","album", or "filename", and $string is the keyword(s) to seach for. If $strict is true then only exact matches are returned. Return an array of matching file paths. Perform the same action as $mpd->search(), but add any matching songs to the current playlist, instead of just returning information about them. Returns an array of all the "album" or "artist" in the music database (as chosen by $type). $artist is an optional parameter, which will only return albums by the specified $artist when $type is "album". Return an array of all the songs in the music database. If $path is specified, then it only returns songs matching the directory/path. Returns an array of hashes containing all the paths and metadata about songs in the music database. If $path is specified, then it only returns songs matching the directory/path. Returns an array of hashes containing all the paths and metadata about songs in the specified directory. If no directory is specified, then only the songs/directories in the root directory are listed.

Retrieving information from current playlist
Return a hash of metadata for the song currently playing. Return an arrayref containing a hashref of metadata for each of the songs in the current playlist. Return a hash of hashref with all the differences in the playlist since playlist $plversion. Returns an a hash containing information about song number $song. If $fromid is true, then $song is the ID of the song. Returns an a hash containing information about song ID $songid. Return the 'title string' of song number $song. The 'title' is the artist and title of the song. If the artist isn't available, then just the title is returned. If there is no title available, then the filename is returned. If $song is not specified, then the 'title' of the current song is returned. Returns the current position and duration of the current song. String is formatted at "M:SS/M:SS", with current time first and total time after. Return current timing information in various different formats contained in a hashref with the following keys: You can find more information on the mpd project on its homepage at <http://www.musicpd.org>, or its wiki <http://mpd.wikia.com>. Regarding this Perl module, you can report bugs on CPAN via <http://rt.cpan.org/Public/Bug/Report.html?Queue=Audio-MPD>. Audio::MPD development takes place on <audio-mpd@googlegroups.com>: feel free to join us. (use <http://groups.google.com/group/audio-mpd> to sign in). Our subversion repository is located at <https://svn.musicpd.org>. Written by: Tue Abrahamsen <tue.abrahamsen@gmail.com> Jerome Quelin <jquelin@cpan.org> Documented by: Nicholas J. Humfrey <njh@aelius.com> Jerome Quelin <jquelin@cpan.org> Copyright (c) 2005 Tue Abrahamsen Copyright (c) 2006 Nicholas J. Humfrey Copyright (c) 2007 Jerome Quelin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.