This is the code that streams MP3 files to the decoder.
sub send_stream {
my ($r,$file,$url) = @_;
my $info = fetch_info($file);
return DECLINED unless $info; # not a legit mp3 file?
open (FILE,$file) || return DECLINED;
my ($base) = $file =~ m!([^/]+)$!;
$base =~ s/\.\w+$//;
my $title = $info->{title} || $base;
foreach ( qw(artist album year comment) ) {
$title .= ', ' . $info->{$_} if defined $info->{$_};
}
my $genre = $info->{genre} || 'unknown';
$r->print("ICY 200 OK\r\n");
$r->print("icy-notice1:<BR>This stream requires a shoutcast/icecast compatible player.<BR>\r\n");
$r->print("icy-notice2:Apache::MP3 module<BR>\r\n");
$r->print("icy-name:$title\r\n");
$r->print("icy-genre:$genre\r\n");
$r->print("icy-url:",'http://',$r->hostname,':',$r->server->port,"\r\n");
$r->print("icy-pub:1\r\n");
$r->print("icy-br:$info->{BITRATE}\r\n");
$r->print("\r\n");
return OK if $r->header_only;
my $buffer;
$r->print($buffer) while read(FILE,$buffer,2048);
return OK;
}
1;
__END__
|
|
| Contents | Next |