views:

266

answers:

1

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. 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";
+3  A: 

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. :)

brian d foy
So how do I go about constructing a playlist using perl?
cb
Well, you find out which player is on the client side, then find out what format it uses for a playlist, then do that.
brian d foy
Okay, I've been reading up on .m3u's, but I can't seem to figure out what to do after the first header. What is the player expecting next? #print the header print $cgi->header(-type=>'audio/x-mpegurl',-expires=>'now'); #print the filename, directory???Thanks Mr. Foy for all your assistance.CB
cb