What is a better way to stream audio with Perl CGI?
Stackoverflow:
For a cs assigment I am using the following code to stream audio. However, now I would like to add the ability to stream files successively, as in a playlist, how can I modify my code to accommodate this? I would like to have a text file of filenames that my script passes through sequentially streaming each.开发者_如何学Go Is this possible? I've spent a good bit of time googling yet found few relevant links.
Thanks, CB#!/usr/bin/perl
use strict;
use CGI::Carp qw/fatalsToBrowser/;
open(OGGFILE, "../HW1/OGG/ACDC.ogg") or die "open error";
my $buffer;
print "Content-type: audio/ogg\n\n";
binmode STDOUT;
while( read(OGGFILE, $buffer, 16384)){
print $buffer;
}
close(OGGFILE);
Update:
I've since modified my code to create a playlist and it seems to be working well. However, for this to work, I am storing my music files in my html folder, available for all to see. Is it a simple matter of changing file permissions to prevent direct linking and visibility? Is it possible for me to modify this program so that it streams the files from a folder outside of /html?
Thanks CB
#!/usr/bin/perl
use strict;
use CGI qw/:standard/;
use CGI::Pretty qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
print header(-type=>'audio/x-mpegurl',-expires=>'now');
printf "#EXTM3U\n";
printf "#EXTINF:-1,Some ACDC song\n";
printf "http://www.mywebserver/MP3/ACDC.ogg\n";
printf "#EXTINF:-1,Some Pink Floyd Song\n";
printf "http://www.mywebserver.com/MP3/PinkFloyd.ogg\n";
For the players I've dealt with, I had to provide a specially formatted playlist that listed the sequence of audio files. The player then requested the audio files as it needed them. You'll have one program to serve that playlist, and another to serve individual audio files.
As for your current program, I'd get the Perl program completely out of the way. Just let the web server handle it, which will be much faster. Your program doesn't do anything the web server doesn't already do for you, so don't make it do the extra work. :)
精彩评论