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

NAME

MP3::Daemon - a daemon that possesses mpg123

SYNOPSIS

Fork a daemon

    MP3::Daemon->spawn($socket_path);

Start a server, but don't fork into background

    my $mp3d = MP3::Daemon->new($socket_path)
    $mp3d->main;

You're a client wanting a socket to talk to the daemon

    my $client = MP3::Daemon->client($socket_path);
    print $client @command;

REQUIRES

Audio::Play::MPG123

This is used to control mpg123 in remote-mode.

Pod::Usage

This is an optional module that bin/mp3 uses to generate help messages.

IO::Socket::UNIX

This is for client/server communication.

IO::Select

I like the OO interface. I didn't feel like using normal select() and messing with vec().

DESCRIPTION

MP3::Daemon provides a server that controls mpg123. Clients such as /bin/mp3 may connect to it and request the server to manipulate its internal playlists.

METHODS

MP3::Daemon relies on unix domain sockets to communicate. The socket requires a place in the file system which is referred to as $socket_path in the following descriptions.

new $socket_path

This instantiates a new MP3::Daemon.

    my $mp3d = MP3::Daemon->new("$ENV{HOME}/.mp3/mp3_socket");
main

This starts the event loop. This will be listening to the socket for client requests while polling mpg123 in times of idleness. This method will never return.

    $mp3d->main;
spawn $socket_path

This combines new() and main() while also forking itself into the background. The spawn method will return immediately to the parent process while the child process becomes an MP3::Daemon that is waiting for client requests.

    MP3::Daemon->spawn("$ENV{HOME}/.mp3/mp3_socket");
client $socket_path

This is a factory method for use by clients who want a socket to communicate with a previously instantiated MP3::Daemon.

    my $client = MP3::Daemon->client("$ENV{HOME}/.mp3/mp3_socket");

Client API

These methods are usually not invoked directly. They are invoked when a client makes a request. The protocol is very simple. The first line is the name of the method. Each argument to the method is specified on successive lines. A final blank line signifies the end of the request.

    0   method name
    1   $arg[0]
    .   ...
    n-1 $arg[n-2]
    n   /^$/

Example:

    print $client <<REQUEST;
    play
    5

    REQUEST

This plays $self->{playlist}[5].

DIAGNOSTICS

I need to be able to report errors in the daemon better. They currently go to /dev/null. I need to learn how to use syslog.

COPYLEFT

Copyleft (c) 2001 John BEPPU. All rights reversed. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

John BEPPU <beppu@binq.org>

SEE ALSO

mpg123(1), Audio::Play::MPG123(3pm), pimp(1p), mpg123sh(1p), mp3(1p)