Audio-MPD

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

 - now that AM::Collection is here, AM's test coverage is up to 82.5% \o/

**

0.14.0 Sat Mar 17 13:29:57 CET 2007
 - implementation of Audio::MPD::Item: instead of returning some random hash
   reference, Audio::MPD now returns AMI objects.
 - renamed methods:
   . get_current_song()      -> current()
   . get_song_info()         -> song()
   . get_song_info_from_id() -> songid()
   . get_title()             -> AMI::Song::as_string()
   . pl_changes()            -> pl_changes()
 - pl_changes() now return an array ref instead of a hash with positions as key
 - test coverage of Audio::MPD up to 66.5%

**

0.13.5 Thu Mar  8 20:22:32 CET 2007
 - get_urlhandlers() renamed to urlhandlers()
 - seekid() defaults to current song

lib/Audio/MPD.pm  view on Meta::CPAN


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) = @_;

lib/Audio/MPD.pm  view on Meta::CPAN

    $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__

lib/Audio/MPD.pm  view on Meta::CPAN

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.

lib/Audio/MPD.pm  view on Meta::CPAN


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

lib/Audio/MPD.pm  view on Meta::CPAN

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

lib/Audio/MPD/Playlist.pm  view on Meta::CPAN


=head2 delete

    $pl->delete( $song [, $song [...] ] );

Remove the specified C<$song> numbers (starting from 0) from the current
playlist. No return value.

=head2 deleteid

    $pl->deleteid( $songid [, $songid [...] ] );

Remove the specified C<$songid>s (as assigned by mpd when inserted in playlist)
from the current playlist. No return value.

=head2 clear

    $pl->clear;

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

=head2 crop

lib/Audio/MPD/Playlist.pm  view on Meta::CPAN


=head2 swap

    $pl->swap( $song1, $song2 );

Swap positions of song number C<$song1> and C<$song2> in the current
playlist. No return value.

=head2 swapid

    $pl->swapid( $songid1, $songid2 );

Swap the postions of song ID C<$songid1> with song ID C<$songid2> in the
current playlist. No return value.

=head2 move

    $pl->move( $song, $newpos );

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

=head2 moveid

    $pl->moveid( $songid, $newpos );

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

=head1 MANAGING PLAYLISTS

=head2 load

    $pl->load( $playlist );

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

=head2 save

t/24-info.t  view on Meta::CPAN

#
# testing song.
$song = $mpd->song(1);
isa_ok( $song, 'Audio::MPD::Common::Item::Song', 'song() returns an AMC::Item::Song object' );
is( $song->file, 'dir1/title-artist-album.ogg', 'song() returns the wanted song' );
$song = $mpd->song; # default to current song
is( $song->file, 'title.ogg', 'song() defaults to current song' );


#
# testing songid.
$song = $mpd->songid(2);
isa_ok( $song, 'Audio::MPD::Common::Item::Song', 'songid() returns an AMC::Item::Song object' );
is( $song->file, 'dir1/title-artist-album.ogg', 'songid() returns the wanted song' );
$song = $mpd->songid; # default to current song
is( $song->file, 'title.ogg', 'songid() defaults to current song' );

t/26-playback.t  view on Meta::CPAN

is( $mpd->status->state, 'play', 'play() starts playback' );
$mpd->play(2);
is( $mpd->status->song,       2, 'play() can start playback at a given song' );

$mpd->play(0);
$mpd->pause;
sleep 1;
$mpd->playid;
is( $mpd->status->state, 'play', 'playid() starts playback' );
$mpd->playid(1);
is( $mpd->status->songid,     1, 'playid() can start playback at a given song' );


#
# testing pause.
$mpd->pause(1);
is( $mpd->status->state, 'pause', 'pause() forces playback pause' );
$mpd->pause(0);
is( $mpd->status->state, 'play', 'pause() can force playback resume' );
$mpd->pause;
is( $mpd->status->state, 'pause', 'pause() toggles to pause' );

t/26-playback.t  view on Meta::CPAN

    $mpd->seek( 1, 2 );
    is( $mpd->status->song,     2, 'seek() can change the current track' );
    is( $mpd->status->time->sofar_secs, 1, 'seek() seeks in the song' );
    $mpd->seek;
    is( $mpd->status->time->sofar_secs, 0, 'seek() defaults to beginning of song' );
    $mpd->seek(1);
    is( $mpd->status->time->sofar_secs, 1, 'seek() defaults to current song ' );


    $mpd->seekid( 1, 1 );
    is( $mpd->status->songid,   1, 'seekid() can change the current track' );
    is( $mpd->status->time->sofar_secs, 1, 'seekid() seeks in the song' );
    $mpd->seekid;
    is( $mpd->status->time->sofar_secs, 0, 'seekid() defaults to beginning of song' );
    $mpd->seekid(1);
    is( $mpd->status->time->sofar_secs, 1, 'seekid() defaults to current song' );
}

t/40-playlist.t  view on Meta::CPAN

$pl->add( 'dir1/title-artist.ogg' );
is( $mpd->status->playlistlength, $nb+3, 'add() songs' );


#
# testing song removal.
$pl->clear;
$pl->add( 'title.ogg' );
$pl->add( 'dir1/title-artist-album.ogg' );
$pl->add( 'dir1/title-artist.ogg' );
$mpd->play(0); # to set songid
$mpd->stop;
$nb = $mpd->status->playlistlength;
$pl->delete( reverse 1..2 ); # reverse otherwise mpd will get it wrong
is( $mpd->status->playlistlength, $nb-2, 'delete() songs' );

$nb = $mpd->status->playlistlength;
$pl->deleteid( $mpd->status->songid );
is( $mpd->status->playlistlength, $nb-1, 'deleteid() songs' );



#
# testing playlist clearing
$pl->add( 'title.ogg' );
$pl->add( 'dir1/title-artist-album.ogg' );
$pl->add( 'dir1/title-artist.ogg' );
$nb = $mpd->status->playlistlength;



( run in 3.245 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )