Audio-Moosic

 view release on metacpan or  search on metacpan

lib/Audio/Moosic.pm  view on Meta::CPAN


    return $self->connected;
}

=head2 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.

=cut

sub error {
    my ($self, $error) = @_;

    if($error) {
        push(@{$self->{__errors}}, $error);
    } else {
        return wantarray ?
            @{$self->{__errors}} :
            @{$self->{__errors}}[@{$self->{__errors}} - 1];
    }
}

=head2 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.

=cut

sub call {
    my ($self, $method, @args) = @_;
    return unless $self->connected;
    my $resp = $self->{__rpc_xml_client}->send_request($method, @args);

    unless( ref $resp ) {
        my $error = qq/Lost connection to moosic server: "$resp"/;
        if( my $function = (caller(1))[3]) { $error .= " in $function()"; }
        $self->error($error);
        $self->{__connected} = 0;
        return;
    }

    if( $resp->is_fault ) {
        my $error = 'Error: '. $resp->code .': "'. $resp->string .'"';
        if( my $function = (caller(1))[3]) { $error .= " in $function()"; }
        $self->error($error);
        return;
    }

    return $resp->value;
}

=head2 api_version

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

=cut

sub api_version {
    my $self = shift;
    my $resp = $self->call('api_version') or return;
    return wantarray ? @{$resp} : join('.', @{$resp});
}

=head2 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.

=cut

sub append {
    my ($self, @items) = @_;
    return $self->call('append', RPC::XML::array->new(
                map { RPC::XML::base64->new($_) } @items
    ));
}

=head2 clear

  $moo->clear;

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

=cut

sub clear {
    my $self = shift;
    return $self->call('clear');
}

=head2 crop

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



( run in 1.253 second using v1.01-cache-2.11-cpan-5a3173703d6 )