Audio-MPD
view release on metacpan or search on metacpan
lib/Audio/MPD.pm view on Meta::CPAN
unshift @outputs, Audio::MPD::Common::Output->new(%param);
%param = ();
}
return @outputs;
}
sub output_enable {
my ($self, $output) = @_;
$self->_send_command("enableoutput $output\n");
}
sub output_disable {
my ($self, $output) = @_;
$self->_send_command("disableoutput $output\n");
}
# -- MPD interaction: retrieving info from current state
sub stats {
my ($self) = @_;
my %kv = $self->_cooked_command_as_kv( "stats\n" );
return Audio::MPD::Common::Stats->new(\%kv);
}
sub status {
my ($self) = @_;
my %kv = $self->_cooked_command_as_kv( "status\n" );
my $status = Audio::MPD::Common::Status->new( \%kv );
return $status;
}
sub current {
my ($self) = @_;
my ($item) = $self->_cooked_command_as_items("currentsong\n");
return $item;
}
sub song {
my ($self, $song) = @_;
return $self->current unless defined $song;
my ($item) = $self->_cooked_command_as_items("playlistinfo $song\n");
return $item;
}
sub songid {
my ($self, $songid) = @_;
return $self->current unless defined $songid;
my ($item) = $self->_cooked_command_as_items("playlistid $songid\n");
return $item;
}
# -- MPD interaction: altering settings
sub repeat {
my ($self, $mode) = @_;
$mode = not $self->status->repeat
unless defined $mode; # toggle if no param
$mode = $mode ? 1 : 0; # force integer
$self->_send_command("repeat $mode\n");
}
sub random {
my ($self, $mode) = @_;
$mode = not $self->status->random
unless defined $mode; # toggle if no param
$mode = $mode ? 1 : 0; # force integer
$self->_send_command("random $mode\n");
}
sub fade {
my ($self, $value) = @_;
$value ||= 0;
$self->_send_command("crossfade $value\n");
}
# -- MPD interaction: controlling playback
sub play {
my ($self, $number) = @_;
$number = '' unless defined $number;
$self->_send_command("play $number\n");
}
sub playid {
my ($self, $number) = @_;
$number ||= '';
$self->_send_command("playid $number\n");
}
sub pause {
my ($self, $state) = @_;
$state ||= ''; # default is to toggle
$self->_send_command("pause $state\n");
}
sub stop {
my ($self) = @_;
$self->_send_command("stop\n");
}
sub next {
my ($self) = @_;
$self->_send_command("next\n");
}
sub prev {
my($self) = shift;
$self->_send_command("previous\n");
}
sub seek {
my ($self, $time, $song) = @_;
$time ||= 0; $time = int $time;
$song = $self->status->song if not defined $song; # seek in current song
$self->_send_command( "seek $song $time\n" );
}
sub seekid {
my ($self, $time, $song) = @_;
$time ||= 0; $time = int $time;
$song = $self->status->songid if not defined $song; # seek in current song
$self->_send_command( "seekid $song $time\n" );
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=head1 NAME
Audio::MPD - class to talk to MPD (Music Player Daemon) servers
=head1 VERSION
version 2.004
=head1 SYNOPSIS
use Audio::MPD;
my $mpd = Audio::MPD->new;
$mpd->play;
sleep 10;
$mpd->next;
=head1 DESCRIPTION
L<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 L<Audio::MPD> object is created.
Since mpd is still in 0.x versions, L<Audio::MPD> sticks to latest mpd
(0.15 as time of writing) protocol & behaviour, and does B<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 C<idle> command (new in mpd 0.14)
is B<not> (and will not) be supported in L<Audio::MPD>. This will be
implemented in L<POE::Component::Client::MPD>.
B</!\> Note that L<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 L<POE::Component::Client::MPD> module is way safer - you're advised
to use it instead of L<Audio::MPD>. Or you can try to set C<conntype> to
C<$REUSE> (see L<Audio::MPD> constructor for more details), but you
would be then on your own to deal with disconnections.
=head2 Searching the collection
To search the collection, use the C<collection()> accessor, returning the
associated L<Audio::MPD::Collection> object. You will then be able to call:
$mpd->collection->all_songs;
lib/Audio/MPD.pm view on Meta::CPAN
=head2 volume
$mpd->volume( [+][-]$volume );
Sets the audio output volume percentage to absolute C<$volume>. If
C<$volume> is prefixed by '+' or '-' then the volume is changed
relatively by that value.
=head2 outputs
my @outputs = $mpd->outputs( );
Return a list of C<Audio::MPD::Common::Outputs> with all outputs
available within MPD.
=head2 output_enable
$mpd->output_enable( $output );
Enable the specified audio output. C<$output> is the ID of the audio
output.
=head2 output_disable
$mpd->output_disable( $output );
Disable the specified audio output. C<$output> is the ID of the audio
output.
=head1 RETRIEVING INFO FROM CURRENT STATE
=head2 stats
my $stats = $mpd->stats;
Return an L<Audio::MPD::Common::Stats> object with the current statistics
of MPD. See the associated pod for more information.
=head2 status
my $status = $mpd->status;
Return an L<Audio::MPD::Common::Status> object with various information on
current MPD server settings. See the associated pod for more information.
=head2 current
my $song = $mpd->current;
Return an L<Audio::MPD::Common::Item::Song> representing the song currently
playing.
=head2 song
my $song = $mpd->song( [$song] );
Return an L<Audio::MPD::Common::Item::Song> representing the song number
C<$song>. If C<$song> is not supplied, returns the current song.
=head2 songid
my $song = $mpd->songid( [$songid] );
Return an L<Audio::MPD::Common::Item::Song> representing the song with id
C<$songid>. If C<$songid> is not supplied, returns the current song.
=head1 ALTERING MPD SETTINGS
=head2 repeat
$mpd->repeat( [$repeat] );
Set the repeat mode to C<$repeat> (1 or 0). If C<$repeat> is not
specified then the repeat mode is toggled.
=head2 random
$mpd->random( [$random] );
Set the random mode to C<$random> (1 or 0). If C<$random> is not
specified then the random mode is toggled.
=head2 fade
$mpd->fade( [$seconds] );
Enable crossfading and set the duration of crossfade between songs. If
C<$seconds> is not specified or $seconds is 0, then crossfading is
disabled.
=head1 CONTROLLING PLAYBACK
=head2 play
$mpd->play( [$song] );
Begin playing playlist at song number C<$song>. If no argument supplied,
resume playing.
=head2 playid
$mpd->playid( [$songid] );
Begin playing playlist at song ID C<$songid>. If no argument supplied,
resume playing.
=head2 pause
$mpd->pause( [$state] );
Pause playback. If C<$state> is 0 then the current track is unpaused,
if C<$state> is 1 then the current track is paused.
Note that if C<$state> is not given, pause state will be toggled.
=head2 stop
$mpd->stop;
Stop playback.
=head2 next
$mpd->next;
Play next song in playlist.
=head2 prev
$mpd->prev;
Play previous song in playlist.
=head2 seek
$mpd->seek( $time, [$song]);
Seek to C<$time> seconds in song number C<$song>. If C<$song> number is
not specified then the perl module will try and seek to C<$time> in the
current song.
=head2 seekid
$mpd->seekid( $time, $songid );
Seek to C<$time> seconds in song ID C<$songid>. If C<$song> number is
not specified then the perl module will try and seek to C<$time> in the
current song.
=for Pod::Coverage BUILD
=head1 SEE ALSO
You can find more information on the mpd project on its homepage at
L<http://www.musicpd.org>.wikia.com>.
Original code (2005) by Tue Abrahamsen C<< <tue.abrahamsen@gmail.com> >>,
documented in 2006 by Nicholas J. Humfrey C<< <njh@aelius.com> >>.
You can look for information on this module at:
=over 4
=item * Search CPAN
L<http://metacpan.org/release/Audio-MPD>
=item * See open / report bugs
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Audio-MPD>
=item * Mailing-list
L<http://groups.google.com/group/audio-mpd>
=item * Git repository
L<http://github.com/jquelin/audio-mpd.git>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/Audio-MPD>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Audio-MPD>
=back
=head1 AUTHOR
Jerome Quelin
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2007 by Jerome Quelin.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 0.940 second using v1.01-cache-2.11-cpan-ceb78f64989 )