Scroll to navigation

Audio::Moosic(3pm) User Contributed Perl Documentation Audio::Moosic(3pm)


Audio::Moosic - Moosic client library for Perl


  use Audio::Moosic;
  $moo = Audio::Moosic::Unix->new();
  print $moosic->current, "\n";


Audio::Moosic acts as a client for the musical jukebox program Moosic ( by Daniel Pearson <>.

Using Audio::Moosic you can connect to a moosic server either via an UNIX socket or an INET socket.



  $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.


  $moo->connect('', 9876);

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



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



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


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

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


  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.


  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.


  my $error = $moo->error;

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 occurred. If you call error() in list context the whole error array of the Audio::Moosic instance is returned.


  $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 occurred. You should try to reconnect.

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

If any error occurred 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 = $moo->api_version;
  $api = $moo->api_version;

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


  $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.



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


  $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 integers 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.


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

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


  print $moo->current;

Return the name of the current playing song.


  print $moo->current_time;

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


  $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.


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

Remove all queued items referenced by list of positions.



Tell the server to terminate itself.


  $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().


  $limit = $moo->get_history_limit;

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


  @config = $moo->getconfig;

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



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


See halt_queue().


  %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 },


  %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


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

Insert items at a given position in the queue.


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

Check whether the loop mode is on or not.


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

Check whether the current song is paused or not.


  if($moo->is_queue_running) {

Check whether the queue consumption (advancement) is activated.


  $time = $moo->last_queue_update

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


  $length = $moo->length

Return the number of items in the song queue.


  @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.


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

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


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

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



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.



Do nothing, successfully.



Pause the currently playing song.


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

Add items to the beginning of the queue.



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.



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


  $length = $moo->queue_length;

Return the number of items in the song queue.



Tell the server to reread its player configuration file.


  $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.


  $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.


  $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.



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


See run_queue().



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



Turn loop mode on or off.


  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.


  $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.



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.


  $moo->sort(4, 6);

Arrange the contents of the queue into sorted order.



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.


  $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.


  $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.


  $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.


  @methods = $moo->listMethods;

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


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

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


  $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



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



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



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



Unpauses the current song.


  $version = $moo->version;

Return the Moosic server's version string.


The following methods aren't methods defined by the moosic API but should be useful when dealing with a moosic server.



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


  $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.


check arguments more strictly

especially for constructors.

If you find some others please report them to Florian Ragwitz <>


  • implement system_multicall
  • improve client_config
  • maybe use autoloader to load subs on demand

    create the method arguments from methodSignature.


moosic(1), moosicd(1),


Florian Ragwitz <>


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.

2018-08-31 perl v5.26.2