NAME
Audio::Play::MPG123 - a frontend to mpg123 version 0.59r and beyond.
SYNOPSIS
use Audio::Play::MPG123;
$player = new Audio::Play::MPG123;
$player->load("kult.mp3");
print $player->artist,"\n";
$player->poll(1) until $player->stat == 0;
$player->load("http://x.y.z/kult.mp3");
# see also mpg123sh from the tarball
DESCRIPTION
This is a frontend to the mpg123 player. It works by starting an external mpg123 process with the -R
option and feeding commands to it.
METHODS
- new
-
This creates a new player object and also starts the mpg123 process.
- load(<path or url>)
-
Immediately loads the specified file (or url, http:// and file:// forms supported) and starts playing it.
- pause
-
Pauses or unpauses the song.
state
can be used to find out about the current mode. - jump
-
Jumps to the specified frame of the song. If the number is prefixed with "+" or "-", the jump is relative, otherweise it is absolute.
- stop
-
Stops the currently playing song and unloads it.
- statfreq(rate)
-
Sets the rate at which automatic frame updates are sent by mpg123.
0
turns it off, everything else is the average number of frames between updates. This can be a floating pount value, i.e.$player->statfreq(0.5/$player->tpf);
will set two updates per sond (one every half a second).
- state
-
Returns the current state of the player:
0 stopped, not playing anything 1 paused, song loaded but not playing 2 playing, song loaded and playing
- poll(<wait>)
-
Parses all outstanding events and status information. If
wait
is zero it will only parse as many messages as are currently in the queue, if it is one it will wait until at least one event occured.This can be used to wait for the end of a song, for example. This function should be called regularly, since mpg123 will stop playing when it can't write out events because the perl program is no longer listening...
- title artist album year comment genre url type layer samplerate mode mode_extension bpf channels copyrighted error_protected title artist album year comment genre emphasis bitrate extension
-
These accessor functions return information about the loaded song. Information about the
artist
,album
,year
,comment
orgenre
might not be available and will be returned asundef
. - tpf
-
Returns the "time per frame", i.e. the time in seconds for one frame. Useful with the
jump
-method:$player->jump (60/$player->tpf);
Jumps to second 60.
- IN
-
returns the input filehandle from the mpg123 player. This can be used for selects() or poll().
AUTHOR
Marc Lehmann <pcg@goof.com>.
SEE ALSO
perl(1).