Audio::Daemon::MPG321 - A song queue daemon for Audio::Play::MPG321.
use Audio::Daemon::MPG321; my $player = new Audio::Daemon::MPG321 ("/home/dabreegster/foo.mp3", "/home/dabreegster/bar.mp3");
$SIG{CHLD} = 'IGNORE'; $player->add("/home/dabreegster/blah.mp3");
while (1) {
until ($player->{player}->state() == 0) {
$player->{player}->poll();
select(undef, undef, undef, 1.0);
}
$player->{pointer}++;
unless ($player->{queue}->[$player->{pointer}]) {
exit 0;
} else {
$player->load();
}
}
This daemonizes Audio::Play::MPG321, or at least gives it the ability to manage a song queue. You can build a simple queue of songs and move between them.
Note the infinite loop in the synopsis. You must put this in your program or the queue won't work! All it does is keep Audio::Play::MPG321's knowledge of the state of the player fresh and continously tests to see if one song is over so the next can be loaded. The code is kept out of the module itself because this process must be done, one way or the other, and forking in the module itself is very messy. The example loop will work fine and you may modify it any way you like to incoorporate it into your frontend, as long as you poll the player, test to see if the song is finished yet, and load the next song in the queue (If there is one!) when it is time to do so.
This method creates a new instance of the daemon and does everything Audio::Play::MPG321 does. It also starts playing the first song in the queue. It takes a list of songs to play.
This immediatly starts to play the song in the queue that has the same index as the pointer attribute. In other words, it plays the current song, where current is defined by the pointer.
This takes a list of songs to be added to the end of the queue.
This takes a list of songs to be spliced in the queue after the current song.
This advances the pointer and plays the next song. If you reach the end of the
queue and try to call next, the daemon will be stopped. See stop().
This moves the pointer back one and plays the previous song. If you reach the
beginning of the queue and try to call prev, the daemon will be stopped. See
stop(). The pointer is not allowed to be negative!
This forces a pause.
This forces a resume.
This pauses if playing and resumes if paused.
This starts the current song over.
This takes one argument: The number of seconds to advance within the song. If you try to advance beyond the song, the state will change to 0.
This takes one argument: The number of seconds to skip backwards within the
song. If you try to advance to a time before the song, it will act as if
restart() had been called. This is the default MPG321 behavior.
This causes the MPG321 player to exit, so have a signal handler for CHLD ready to reap some zombies.
Da-Breegster <scarlino@bellsouth.net>