|
Audio::Play::MPG123 - a frontend to mpg123 version 0.59r and beyond. |
Audio::Play::MPG123 - a frontend to mpg123 version 0.59r and beyond.
use Audio::Play::MPG123;
$player = new Audio::Play::MPG123;
$player->load("kult.mp3");
print $player->artist,"\n";
$player->poll(1) until $player->state == 0;
$player->load("http://x.y.z/kult.mp3");
# see also mpg123sh from the tarball
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.
While the standard mpg123 player can be used to play back mp3's using
this module you will encounter random deadlocks, due to bugs in its
communication code. Also, many features (like statfreq) only work with
the included copy of mpg123, so better use that one before deciding that
this module is broken.
(In case you wonder, the mpg123 author is not interested in including these fixes and enhancements into mpg123).
Most methods can be either BLOCKING (they wait until they get an answer,
which usually takes half a mpeg frame of playing time), NONBLOCKING (the
functions return as soon as they send their message, which is usallly
instant) or CACHING (the method returns some cached data which only gets
refreshed by an asynchronous STAT event or an explicit call to state).
mpg123args an arrayreg with additional arguments for the mpg123 process
file:// or http:// then consider prefixing all
your paths with file:///. Returns a true status when the song could be
started, false otherwise.
statfreq and infrequent calls to poll is often a better
strategy.
state (or paused) can be used to find
out about the current mode.
state, i.e. zero when something is playing
and non-zero when the player is stopped or paused.
statfreq(rate) [NONBLOCKING]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 second (one every half a second).
0 stopped, not playing anything 1 paused, song loaded but not playing 2 playing, song loaded and playing
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...
artist, album, year, comment or
genre might not be available and will be returned as undef.
The accessor function frame returns a reference to an array containing
the frames played, frames left, seconds played, and seconds left in this
order. Seconds are returned as floating point numbers.
jump-method:
$player->jump (60/$player->tpf);
Jumps to second 60.
selects() or poll().
Marc Lehmann <schmorp@schmorp.de>.
perl(1).
|
Audio::Play::MPG123 - a frontend to mpg123 version 0.59r and beyond. |