The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Audio::MPD - Class for talking to MPD (Music Player Daemon) servers

SYNOPSIS

    use Audio::MPD;

    my $mpd = Audio::MPD->new();
    $mpd->play();
    sleep 10;
    $mpd->next();

DESCRIPTION

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.

METHODS

Constructor

new( [[$password@]$host], [$port] )

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

$mpd->ping()

Sends a ping command to the mpd server.

$mpd->version()

Return the version number for the server we are connected to.

$mpd->kill()

Send a message to the MPD server telling it to shut down.

$mpd->password( [$password] )

Change password used to communicate with MPD server to $password. Empty string is assumed if $password is not supplied.

$mpd->updatedb( [$path] )

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.

$mpd->stats()

Return a hashref with the number of artists, albums, songs in the database, as well as mpd uptime, the playtime of the playlist / the database and the last update of the database

$mpd->status()

Return a Audio::MPD::Status object with various information on current MPD server settings. Check the embedded pod for more information on the available accessors.

$mpd->send_password( password )

Send a plaintext password to the server, which can enable optionally password protected functionality.

$mpd->get_urlhandlers()

Return an array of supported URL schemes.

Changing MPD settings

$mpd->repeat( [$repeat] )

Set the repeat mode to $repeat (1 or 0). If $repeat is not specified then the repeat mode is toggled.

$mpd->random( [$random] )

Set the random mode to $random (1 or 0). If $random is not specified then the random mode is toggled.

$mpd->fade( [$seconds] )

Enable crossfading and set the duration of crossfade between songs. If $seconds is not specified or $seconds is 0, then crossfading is disabled.

$mpd->volume( [+][-]$volume )

Sets the audio output volume percentage to absolute $volume. If $volume is prefixed by '+' or '-' then the volume is changed relatively by that value.

$mpd->output_enable( $output )

Enable the specified audio output. $output is the ID of the audio output.

$mpd->output_disable( $output )

Disable the specified audio output. $output is the ID of the audio output.

Controlling playback

$mpd->play( [$number] )

Begin playing playlist at song number $number.

$mpd->playid( [$songid] )

Begin playing playlist at song ID $songid.

$mpd->pause( [$state] )

Pause playback. If $state is 0 then the current track is unpaused, if $state is 1 then the current track is paused.

Note that if $state is not given, pause state will be toggled.

$mpd->stop()

Stop playback.

$mpd->next()

Play next song in playlist.

$mpd->prev()

Play previous song in playlist.

$mpd->seek( $time, [$song])

Seek to $time seconds. If $song number is not specified then the perl module will try and seek to $time in the current song.

$mpd->seekid( $time, $songid )

Seek to $time seconds in song ID $songid.

Playlist handling

$mpd->add( $path )

Add the song identified by $path (relative to MPD's music directory) to the current playlist. No return value.

$mpd->delete( $song )

Remove song number $song from the current playlist. No return value.

$mpd->deleteid( $songid )

Remove the specified $songid from the current playlist. No return value.

$mpd->clear()

Remove all the songs from the current playlist. No return value.

$mpd->crop()

Remove all of the songs from the current playlist *except* the song currently playing.

$mpd->swap( $song1, $song2 )

Swap positions of song number $song1 and $song2 on the current playlist. No return value.

$mpd->swapid( $songid1, $songid2 )

Swap the postions of song ID $songid1 with song ID $songid2 on the current playlist. No return value.

$mpd->shuffle()

Shuffle the current playlist. No return value.

$mpd->move( $song, $newpos )

Move song number $song to the position $newpos. No return value.

$mpd->moveid( $songid, $newpos )

Move song ID $songid to the position $newpos. No return value.

$mpd->load( $playlist )

Load list of songs from specified $playlist file. No return value.

$mpd->save( $playlist )

Save the current playlist to a file called $playlist in MPD's playlist directory. No return value.

$mpd->rm( $playlist )

Delete playlist named $playlist from MPD's playlist directory. No return value.

Retrieving information from the collection

$mpd->search( $type, $string, [$strict] )

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.

$mpd->searchadd( $type, $string )

Perform the same action as $mpd->search(), but add any matching songs to the current playlist, instead of just returning information about them.

$mpd->list( $type, [$artist] )

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".

$mpd->listall( [$path] )

Return an array of all the songs in the music database. If $path is specified, then it only returns songs matching the directory/path.

$mpd->listallinfo( [$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.

$mpd->lsinfo( [$directory] )

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

$mpd->get_current_song_info( )

Return a hash of metadata for the song currently playing.

$mpd->playlist( )

Return an arrayref containing a hashref of metadata for each of the songs in the current playlist.

$mpd->playlist_changes( $plversion )

Return a hash of hashref with all the differences in the playlist since playlist $plversion.

$mpd->get_song_info( $song )

Returns an a hash containing information about song number $song.

$mpd->get_song_info_from_id( $songid )

Returns an a hash containing information about song ID $songid.

$mpd->get_title( [$song] )

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.

$mpd->get_time_format( )

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.

$mpd->get_time_info( )

Return current timing information in various different formats contained in a hashref with the following keys:

minutes_so_far
seconds_so_far
time_so_far
minutes
seconds
percentage
time_total
seconds_total
seconds_left
time_left

SEE ALSO

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.

AUTHORS

Jerome Quelin <jquelin@cpan.org>

Original code by Tue Abrahamsen <tue.abrahamsen@gmail.com>, documented by Nicholas J. Humfrey <njh@aelius.com>.

COPYRIGHT AND LICENSE

Copyright (c) 2005 Tue Abrahamsen <tue.abrahamsen@gmail.com>

Copyright (c) 2006 Nicholas J. Humfrey <njh@aelius.com>

Copyright (c) 2007 Jerome Quelin <jquelin@cpan.org>

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.