SYNOPSIS

  use Audio::Moosic;

  $moo = Audio::Moosic::Unix->new();

  $moosic->append('/home/me/somewhat.ogg');
  $moosic->play;
  print $moosic->current, "\n";
  $moosic->pause;
  ...

DESCRIPTION

Audio::Moosic acts as a client for the musical jukebox programm Moosic (http://nanoo.org/~daniel/moosic/) by Daniel Pearson <[email protected]>.

Using Audio::Moosic you can connect to a moosic server either via an \s-1UNIX\s0 socket or an \s-1INET\s0 socket.

METHODS

new

$moo = Audio::Moosic::Unix->new(); $moo = Audio::Moosic::Unix->new('/tmp/moosic/socket'); $moo = Audio::Moosic::Inet->new('localhost', 8765);

Constructor. Initializes the class and invokes the connect method. If you're creating a Audio::Moosic::Unix object you can give the location of your moosic socket as parameter. If not ~/.moosic/socket is used. If you're creating a Audio::Moosic::Inet instance you need to pass host and port as arguments.

You can't create an instance of Audio::Moosic itself. Use Unix or Inet subclass.

If the object was able to connect to the moosic server a reference to the object instance is returned. If the connection failed $@ is set and undef returned.

connect

$moo->connect('foobar.com', 9876);

Connect to the moosic server. You normally don't need to run this method in your moosic client.

disconnect

$moo->disconnect;

Disconnect from the moosic daemon. No more calls will be sent to the server after calling this method. You'll need to reconnect() first.

reconnect

$moo->reconnect;

Disconnects from the server if you're connected and tries to reconnect.

connected

$moo->reconnect unless $moo->connected;

Check whether you're connected to the moosic server or not.

client_config

print $moo->client_config('location'); $conf = $moo->client_config();

Reads the moosic clients config. If a $key argument is given it returns only the value associated with that key, if not the whole config hash.

Would it be a good idea to make the user able to edit the client_config here? Suggestions or maybe patches are welcome.

ping

die unless $moo->ping;

Checks if we're still connected. This method checks the connection explicitly by calling the no_op server method. connected() only checks the value of the 'connected' object property.

error

my $error = $moo->error; $moo->error('Whaaa!');

If an argument is given it adds the error string to the internal error array. If called in scalar context it returns the last error occured. If you call error() in list context the whole error array of the Audio::Moosic instance is returned.

call

$moo->call('foo'); $moo->call('bar', RPC::XML::int->new(3));

This method calls a xml-rpc method on the moosic server. The first argument should be the method name. The arguments of that method should follow behind.

If the request to the moosic server could not be sent the Audio::Moosic instance disconnects from the server and puts the error message into the internal error array. Access it via error(). The object won't send any calls anymore if such an error occured. You should try to reconnect.

If the request could be sent, but returned an error the error message is added to the error array accessable via error().

If any error occured call() returns undef. If everything went fine the value of the response is returned.

Normally you don't need to call this method. It is only used by other moosic methods to send their calls more easily. If a new moosic method is not supported by this library yet you'll maybe need to use call() manually. Please notice me if that happens so I'll add the new method.

api_version

@api = $moo->api_version; $api = $moo->api_version;

Return the moosic servers \s-1API\s0 version. If called in scalar context a version string like '1.3' is returned. In list context the mayor and minor numbers of the \s-1API\s0 version are returned.

append

$moo->append('/home/florian/whatever.ogg'); $moo->append('/home/florian/foo.ogg', '/home/florian/bar.mp3');

Add songs to the moosic queue. The files to add should be the arguments for the append method. append() returns 1 if there were no errors or something false if there were some.

clear

$moo->clear;

Clears the moosic queue. Only the current song remains playing.

crop

$moo->crop(4); $moo->crop(3, 4);

Remove all playlist items that don't fall within a given range. If the range is represented by one integer all items whose index is greater than or equal to the value will be removed. Two intergers represent all items whose index is greater than or equal to the value of first integer and less than the value of the second integer.

crop_list

$moo->crop_list(1, 4, 3);

Remove all queued items exept those referenced by a list of positions.

current

print $moo->current;

Return the name of the current playing song.

current_time

print $moo->current_time;

Return the amount of time the current song has been playing.

cut

$moo->cut(3); $moo->cut(4, 10);

Remove all queued items that fall within a given range. See crop() for details on how that range should look like.

cut_list

$moo->cut_list(3, 7, 9);

Remove all queued items referenced by list of positions.

die

$moo->die;

Tell the server to terminate itself.

filter

$moo->filter('foo'); $moo->filter('bar', 4); $moo->filter('moo', 7, 11);

Remove all items that don't match the given regular expression. You may limit this operation to a specific range which is described in crop().

get_history_limit

$limit = $moo->get_history_limit;

Get the limit on the size of the history list stored in servers memory.

getconfig

@config = $moo->getconfig;

Return a list of the server's filetype-player associations.

halt_queue

$moo->halt_queue;

Stop any new songs from being played. Use run_queue() to reverse this state.

haltqueue

See halt_queue().

history

%hist = $moo->history;

Return a list of items that has been recently played. If a positive integer argument is given than no more than number of items will be returned. Otherwise the entire history is printed.

history() returns an array of hashrefs like that:

  @history = (
    { title => 'foo', start => 123.45, stop => 543.21 },
    { title => 'bar', start => 234.56, stop => 654.32 },
    ...
  );

indexed_list

%list = $moo->indexed_list; %list = $moo->indexed_list(1); %list = $moo->indexed_list(2, 5);

List the song queue's contents. If a range is specified, only the items that fall within that range are listed.

indexed_list() returns a hash like that:

  %list = (
    list => [ 'foo', 'bar', 'moo', ... ],
    start => 4
  );

insert

$moo->insert(4, 'foo.ogg', 'bar.mp3');

Insert items at a given position in the queue.

is_looping

$moo->toggle_loop_mode if $moo->is_looping;

Check whether the loop mode is on or not.

is_paused

$moo->toggle_pause if $moo->is_paused;

Check whether the current song is paused or not.

is_queue_running

if($moo->is_queue_running) { ...; }

Check whether the queue consumption (advancement) is activated.

last_queue_update

$time = $moo->last_queue_update

Return the time at which the song queue was last modified.

length

$length = $moo->length

Return the number of items in the song queue.

list

@list = $moo->list(); @list = $moo->list(2); @list = $moo->list(4, 8); $list_ref = $moo->list()

List the song queue's contents. If a range is specified, only the items that fall within that range are listed. Returns an array if called in list context or an array reference if it's called in scalar context.

move

$moo->move(10, 4); $moo->move(4, 7, 1);

Move a range of items to a new position within the queue.

move_list

$moo->move(3, 5, 7, 11);

Move the items referenced by a list of positions to a new position.

next

$moo->next; $moo->next(5);

Stop the current song (if any), and jumps ahead to a song that is currently in the queue. The skipped songs are recorded in the history as if they had been played. When called without arguments, this behaves very much like the skip() method, except that it will have an effect even if nothing is currently playing.

no_op

$moo->no_op

Do nothing, successfully.

pause

$moo->pause;

Pause the currently playing song.

prepend

$moo->prepend('foo.ogg', 'bar.mp3');

Add items to the beginning of the queue.

previous

$moo->previous; $moo->previous(3);

Stops the current song (if any), removes the most recently played song from the history, and puts these songs at the head of the queue. When loop mode is on, the songs at the tail of the song queue are used instead of the most recently played songs in the history.

putback

$moo->putback;

Place the currently playing song at the beginning of the queue.

queue_length

$length = $moo->queue_length;

Return the number of items in the song queue.

reconfigure

$moo->reconfigure;

Tell the server to reread its player configuration file.

remove

$moo->remove('regex'); $moo->remove('regex', 4); $moo->remove('regex', 1, 3);

Remove all items that match the given regular expression. You can limit this operation by giving a range as described in crop() as last argument.

replace

$moo->replace('foo.ogg', 'bar.mp3');

Replace the contents of the queue with the given items. This is equivalent to calling clear() and prepend() in succession, except that this operation is atomic.

reverse

$moo->reverse; $moo->reverse(2); $moo->reverse(5, 7);

Reverse the order of the items in the queue. You can limit this operation by giving a range as described in crop() as last argument.

run_queue

$moo->run_queue;

Allows new songs to be played again after halt_queue() has been called.

runqueue

See run_queue().

set_history_limit

$moo->set_history_limit(44);

Set the limit on the size of the history list stored in memory.

set_loop_mode

$moo->set_loop_mode(0); $moo->set_loop_mode(1);

Turn loop mode on or off.

showconfig

my $config = $moo->showconfig; my %config = $moo->showconfig;

Return the server's player configuration. If showconfig() is called in scalar context a scalar containing the textual description of the configuration is returned. If you call showconfig() in list context a hash which maps the configuration regular expression to the player commands is returned.

shuffle

$moo->shuffle; $moo->shuffle(2); $moo->shuffle(4, 6);

Rearrange the contents of the queue into a random order. You can limit this operation by giving a range as described for crop() as last argument.

skip

$moo->skip;

Skips the rest of the current song to play the next song in the queue. This only has an effect if there actually is a current song.

sort

$moo->sort; $moo->sort(2); $moo->sort(4, 6);

Arrange the contents of the queue into sorted order.

stop

$moo->stop;

Stop playing the current song and stops new songs from playing. The current song is returned to the head of the song queue and is not recorded in the history list. If loop mode is on, the current song won't be placed at the end of the song queue when it is stopped.

sub

$moo->sub('regex', 'substitition'); $moo->sub('regex', 'substitition', 2); $moo->sub('regex', 'substitition', 1, 7);

Perform a regular expression substitution on the items in the queue. You can limit this operation by giving a range as described for crop() as last argument.

sub_all

$moo->sub_all('regex', 'substition'); $moo->sub_all('regex', 'substition', 2); $moo->sub_all('regex', 'substition', 1, 7);

Performs a global regular expression substitution on the items in the queue.

swap

$moo->swap( [7, 10], [ 5 ] );

Swap the items contained in one range with the items contained in the other range. The ranges for the swap() method needs to be passed as array references in contrast to other methods that use ranges.

listMethods

@methods = $moo->listMethods;

Return an array of all available XML-RPC methods on this server.

methodHelp

$help = $moo->methodHelp('sub');

Given the name of a method, return a help string.

methodSignature

$signature = $moo->methodSignature;

Given the name of a method, return an array of legal signatures. Each signature is an array of scalars. The first item of each signature is the return type, and any others items are parameter types. =cut

multicall

$moo->multicall(...);

Process an array of calls, and return an array of results. This is not implemented yet.

toggle_loop_mode

$moo->toggle_loop_mode;

Turn loop mode on if it is off, and turns it off if it is on.

toggle_pause

$moo->toggle_pause;

Pause the current song if it is playing, and unpauses if it is paused.

unpause

$moo->unpause;

Unpauses the current song.

version

$version = $moo->version;

Return the Moosic server's version string.

HELPER METHODS

The following methods aren't methods defined by the moosic \s-1API\s0 but should be usefull when dealing with a moosic server.

play

$moo->play();

Start playing. If the playback is paused it will be unpaused. If the queue is stopped it will be started.

can_play

$moo->append( $song ) if $moo->can_play( $song );

Takes a list of songs as argument and returns all items that can be played by the moosic daemon.

BUGS

  • check arguments more strictly expecially for constructors.

If you find some others please report them to Florian Ragwitz <[email protected]>

TODO

  • implement system_multicall

  • improve client_config

  • maybe use autoloader to load subs on demand create the method arguments from methodSignature.

RELATED TO Audio::Moosic…

moosic\|(1), moosicd\|(1), http://nanoo.org/~daniel/moosic/

AUTHOR

Florian Ragwitz <[email protected]>

COPYRIGHT AND LICENSE

Copyright (C) 2004-2008 by Florian Ragwitz

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.