The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Audio::Daemon::MPG123::Client - The Client portion of Audio::Daemon::MPG123

SYNOPSIS

  use Audio::Daemon::Client;

  my $player = new Audio::Daemon::Client(Server => '10.10.10.1', Port => 9101);

  # add in some mp3's 
  $player->add(qw(Goodbye.mp3 Joey.mp3 Clothes_Of_Sand.mp3));
  # set random mode on
  $player->random(1);

  # status returns a hashref full of useful info
  my $status = $player->status;
  print "Random mode is ".($status->{random}?'On':'Off')."\n";
  print "Current track is \"".$status->{title}.'" by '.$status->{artist}."\n";

DESCRIPTION

This is one possible Client for Audio::Daemon.

This client portion communicates to the Server via UDP message passing and has no dependancies other then IO::Socket and IO::Select.

Most of this is best demostrated by examples, so I'll try to keep the examples up to date.

CONSTRUCTORS

There is but one method to contruct a new Audio::Daemon::Client object:

Audio::Daemon::Client->new(Server => $server, Port => $port, [Log => \&logsub]);

The new method can take the following arguments:

Server

This specifies the IP address of the Audio::Daemon::Server server, it is required.

Port

The port the server is listening on (we snag whatever local port IO::Socket chooses).

Log

This takes a reference to a function that's called for logging purposes, the format passed in is:

    <type>, <msg>, [caller(1)]

    where <type> is one of debug, info, error, crit, warn. <msg> is the text message, and [caller] is the array returned by the second form of the perlfunc caller(). This will give you the method, line number, etc. of where the messagee is coming from. With this logging feature, I don't have to worry about syslog, stdout, or how to report errors or debug info... you do!

METHODS

I tried to stay as close the Audio::Play::MPG123 methods as possible with a few exceptions noted below.

add [list of urls]

Needs to have arguments (array or array ref) of urls to load on the server. If you're calling an mp3 file it obviously needs access by the server, not the client. It can be simple filenames, or urls including http: urls for streaming to the server. If there are tracks already in the playlist on the server these will be tacked on to the end of the list. If random mode is on, it will re-randomize the entire list when it is finished adding (see the random feature).

del [list of index numbers]

Takes either the index number of tracks to remove or the keyword "all" to clear out the tracks. If the player is currently playing a track you removed it will internally call "next" to move the next track. If you remove all tracks, it will cease to play until you add tracks back in.

stop

Stops the player if it's playing, otherwise it won't stop a non-playing player.

play

Starts the player if it's not playing, otherwise it lets a playing player play.

pause

Pauses the player if it's not paused, unpauses if it is paused.

next

Moves to the next track, this should not cause it to start playing if it is isn't currently.

prev

Goes in the opposite direction of next, but again, won't start it playing if it's not.

list

This causes the current playlist to be sent back with the next status update that normally occurs after each instruction (including the list command). The Play List is then accessed via the status method.

jump ([+-]#[s])

Jump is very similiar to the Audio::Play::MPG123 command. It accepts one argument that can get a wee bit complicated but follow me on this, it has three parts, only one part is required:

<plus or minus><a digit><seconds>

This is best described with examples:

10s (moves 10 seconds from the beginning of the track) 165s (moves to 2:35 in the current track) +10s (moves forward 10 seconds from current track position) -10s (moves back 10 seconds from current track position) 10 (moves to the tenth frame -- see the "frame" status)

Most people would avoid the last example, but it's there for compatability issues.

vol ([vol|left], [right)

If you have the Audio::Mixer volume on the server, it will set the volume. If one argument is passed in it will equally set the right and left channels, if two arguments are passed in it will set left and right volumes respectively.

random (1|0)

Turns on or off the random mode. The random playlist is really created when tracks are added or removed from the current playlist. This way each track is played in a "random" order before repeating any single track. If the playlist is modified in any way, the random playlist will be recreated opening the probability that a track will be repeated before all tracks are played.

repeat (1|0)

Turns on or off the repeat function. This doesn't mean it will repeat a track it means that it will wrap around to the beginning of a playlist when the end is reached. With repeat off, it will stop playing once all tracks have been played.

info

This is basically a null command, tell the server to send the current status information which it will do after any command.

status

This is the meat and potatoes of the app.

After every command sent to the server, the server responds with all sorts of information processed behind the scene. Calling this method returns a hash reference to all the information last retrieved from the server. Currently the values in the status are:

state

0 is stopped, 1 is paused, 2 is playing

random

1 or 0 (meaning true of false, yes or no)

repeat

1 or 0

id

Current index (starting at 0) of the track being playing in the playlist.

frame

This is taken directly from c<Audio::Play::MPG123>, so I'd suggest looking there for more detail, but the basic format is <current frame>,<frames remeaining>,<seconds passed>,<seconds remaining>. If you're using a different server, the first numbers have different meanings, check the pod on those servers, the last two arguments are the same across all servers. The frames are determined by the mp3 file (as far as I get it). In order to get the total seconds in the track you'd add up the <seconds passed> and the <seconds remaining>. Again, see c<Audio::Play::MPG123> for details on this.

title, artist, album, genre

The respective value from the MP3 ID3 tag of the current track.

url

The current url (file index position, or other) of current track.

vol

"l,r" value (left comma right), if Audio::Mixer is loaded on the server, otherwise it's undef.

list

Only set after specifically calling "list" and is a reference to an array of urls in the (non-random) order being used by the player.

It might be benificial to double check the keys returned by b<status> as there may be some things added that *gasp* the documentation wasn't updated for.

AUTHOR

Jay Jacobs jayj@cpan.org

SEE ALSO

Audio::Daemon::MPG123

Audio::Play::MPG123

perl(1).

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 256:

=back doesn't take any parameters, but you said =back 4

Around line 262:

You forgot a '=back' before '=head1'

You forgot a '=back' before '=head1'

You forgot a '=back' before '=head1'

You forgot a '=back' before '=head1'

Around line 403:

=back doesn't take any parameters, but you said =back 4