Audio::Play::MPG321 - A frontend to MPG321.


NAME

Audio::Play::MPG321 - A frontend to MPG321.


SYNOPSIS

use Audio::Play::MPG321; my $player = new Audio::Play::MPG321;

$SIG{CHLD} = 'IGNORE'; # May not work everywhere! $SIG{INT} = sub { $player->stop(); exit 0; };

$player->play("/home/dabreegster/foo.mp3"); do { $player->poll(); print $player->{sofar}, " ", $player->{remains}, " ", $player->state(), "\n"; } until $player->state() == 0;


$player->play("/home/dabreegster/bar.mp3");
sleep until $player->state() == 0;


DESCRIPTION

This is a frontend to the MPG321 MP3 player. It talks to it in remote mode and provides constant feedback about the time elapsed so far, the time remaining, and the state of the player. If you use Audio::Play::MPG321 directly, then you will have to do some extra work outside of the module, as demonstrated in the synopsis. If you want to build a basic queue (Play one song, then play another), then you must keep calling poll() to make sure Audio::Play::MPG321 knows how MPG321 is doing and testing state() to be 0.

METHODS

new

This method takes no additional arguments and simply starts MPG321, initialises connections to it, and returns a player object.

poll

Messages from MPG321 will build up unless you call this subroutine routinely. It's perfectly okay to leave the messages there, but if you want to build any sort of music queue or desire any status information, you will need to call this frequently.

parse

This should never be called directly; poll() will call it for you. This just takes a line of input from MPG321 and parses it.

play

This takes a single argument: The full path to a MP3 file. Like the name suggests, it immediatly plays it.

state

This returns a status code: 0 if the song has ended, 1 if the song is paused, or 2 if the song is playing. Frequent calls to poll() are necessary if this information is to be kept current.

toggle

If the player is paused, this resumes it. If it's playing, it'll pause it.

pause

This forces a pause. Pausing while paused yields no effect.

resume

This forces a resume. Resuming while playing yields no effect.

seek

The first argument should be "+" or "-" if that direction in time is desired for the seeking, or undef otherwise. The second argument should be the number of seconds.

stop

The name may be a bit confusing, but since I see no reason to ever force a song into state 0, this closes the player. MPG321 will exit and somewhere along the line, a signal handler for CHLD must be defined to reap the zombie.


AUTHOR

Da-Breegster <dabreegster@gmail.com>