Audio::MPD
Audio::MPD - class to talk 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.
Since mpd is still in 0.x versions, Audio::MPD sticks to latest mpd
(0.14 as time of writing) protocol & behaviour, and does not try to
maintain backward compatibility.
Note that the module will by default connect to mpd before sending any
command, and will disconnect after the command has been issued. This
scheme is far from optimal, but allows us not to care about timeout
disconnections. Because of that, the idle command (new in mpd 0.14)
is not (and will not) be supported in Audio::MPD. This will be
implemented in POE::Component::Client::MPD.
/!\ Note that Audio::MPD is using high-level, blocking sockets.
This means that if the mpd server is slow, or hangs for whatever reason,
or even crash abruptly, the program will be hung forever in this sub.
The POE::Component::Client::MPD module is way safer - you're advised
to use it instead of Audio::MPD. Or you can try to set conntype to
$REUSE (see Audio::MPD constructor for more details), but you
would be then on your own to deal with disconnections.
This is the constructor for Audio::MPD. One can specify the following
options:
$hostname
MPD_HOST, then to 'localhost'. Note that
MPD_HOST can be of the form password@host.
$port
MPD_PORT, then to 6600.
MPD_PASSWORD, then to ''.
$REUSE to reuse the same connection or $ONCE to open a new
connection per command (default)
$password.
Empty string is assumed if $password is not supplied.
$path (relative to MPD's music
directory) is supplied, MPD will only scan it - otherwise, MPD will
rescan its whole collection.
$volume. If
$volume is prefixed by '+' or '-' then the volume is changed
relatively by that value.
$output is the ID of the audio
output.
$output is the ID of the audio
output.
Audio::MPD::Common::Stats object with the current statistics
of MPD. See the associated pod for more information.
Audio::MPD::Common::Status object with various information on
current MPD server settings. Check the embedded pod for more information on
the available accessors.
Audio::MPD::Common::Item::Song representing the song currently
playing.
Audio::MPD::Common::Item::Song representing the song number
$song. If $song is not supplied, returns the current song.
Audio::MPD::Common::Item::Song representing the song with id
$songid. If $songid is not supplied, returns the current song.
$repeat (1 or 0). If $repeat is not
specified then the repeat mode is toggled.
$random (1 or 0). If $random is not
specified then the random mode is toggled.
$seconds is not specified or $seconds is 0, then crossfading is
disabled.
$song. If no argument supplied,
resume playing.
$songid. If no argument supplied,
resume playing.
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.
$time seconds in song number $song. If $song number is
not specified then the perl module will try and seek to $time in the
current song.
$time seconds in song ID $songid. If $song number is
not specified then the perl module will try and seek to $time in the
current song.
To search the collection, use the collection() accessor, returning the
associated Audio::MPD::Collection object. You will then be able to call:
$mpd->collection->random_song;
See Audio::MPD::Collection documentation for more details on available
methods.
To update the playlist, use the playlist() accessor, returning the
associated Audio::MPD::Playlist object. You will then be able to call:
$mpd->playlist->clear;
See Audio::MPD::Playlist documentation for more details on available
methods.
Please report any bugs or feature requests to
bug-audio-mpd@rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Audio-MPD. I will be
notified, and then you'll automatically be notified of progress on your
bug as I make changes.
You can find more information on the mpd project on its homepage at http://www.musicpd.org.wikia.com>.
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 git repository is located at
git://repo.or.cz/audio-mpd.git, and can be browsed at
http://repo.or.cz/w/audio-mpd.git.
You can also look for information on this module at:
Jerome Quelin, <jquelin@cpan.org>
Original code by Tue Abrahamsen <tue.abrahamsen@gmail.com>,
documented by Nicholas J. Humfrey <njh@aelius.com>.
Copyright (c) 2005 Tue Abrahamsen, all rights reserved. Copyright (c) 2006 Nicolas J. Humfrey, all rights reserved. Copyright (c) 2007-2009 Jerome Quelin, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.