Audio-Daemon
view release on metacpan or search on metacpan
Daemon/Shout.pm view on Meta::CPAN
package Audio::Daemon::Shout;
use strict;
use IO::Socket;
use IO::Select;
use Audio::Daemon;
use Shout;
use MP3::Info;
use vars qw(@ISA $VERSION);
@ISA = qw(Audio::Daemon);
$VERSION='0.99Beta';
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
bless $self, $class;
# initilize current playlist
$self->{playlist} = [];
# initialize random index.
$self->{random} = [];
$self->{revrandom} = [];
# initilize my current states of various things
$self->{state} = {random => 0, repeat => 0, state => 0};
$self->connect;
return $self;
}
sub connect {
my $self = shift;
my $config = $self->{Pass};
my %params;
# can also set 'lame' parameter,
# checked for to see if we downsample when streaming.
foreach my $p (qw/ip port mount password icy_compat aim icq irc
dumpfile name url genre description bitrate ispublic/) {
if (defined $self->{Pass}{$p}) {
$self->debug("Setting $p to \"".$config->{$p}."\"");
$params{$p} = $config->{$p};
}
}
my $server = new Shout(%params);
if (! defined $server) {
$self->crit("Failed to initialize Should object: $!");
return;
}
if (! $server->connect) {
$self->crit("Failed to connect to server: ".$server->error);
return;
}
$self->player($server);
}
sub player {
my $self = shift;
$self->{player} = shift if (scalar @_);
return $self->{player};
}
sub stop {
my $self = shift;
$self->{state}{state} = 0;
}
sub play {
my $self = shift;
my $remote = shift;
my $player = $self->player;
if (defined $remote && ref $remote && scalar @{$remote->{args}}) {
if ($self->{state}{random}) {
$self->{state}{renid} = $self->{revrandom}[$remote->{args}[0]];
$self->{state}{regid} = $remote->{args}[0];
}
}
$self->debug("Random is ".($self->{state}{random})?'true':'false');
my $id = $self->{state}{regid};
$self->info("Setting current playlist id to $id and song to ".$self->{playlist}[$id]);
if (! -r $self->{playlist}[$id]) {
$self->crit("File Not Found or Not Readable: ".$self->{playlist}[$id]);
return;
}
$self->{state}{state} = 2;
}
sub pause {
my $self = shift;
$self->{state}{state} = 1 if ($self->{state}{state} == 2);
$self->{state}{state} = 2 if ($self->{state}{state} == 1);
}
sub add {
my $self = shift;
my $remote = shift;
push @{$self->{playlist}}, @{$remote->{args}};
( run in 0.588 second using v1.01-cache-2.11-cpan-39bf76dae61 )