Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

midiplayer.pl

by JSchmitz (Canon)
on Jul 08, 2001 at 04:16 UTC ( #94784=sourcecode: print w/ replies, xml ) Need Help??

Category: CGI Programming
Author/Contact Info jgschmitz@linuxmail.org
Description: Allows you to play midi files on your website.
#!/usr/bin/perl

# To run this script put the following line into the body of your html
+ page.
# <!--#exec cgi="/path/to/bsmidi.cgi"-->

$datafile = "playlist.txt";
 # Location of the playlist file.
 # An example is included in the zip file.

$width = "0";
 # The width of the control box.

$height = "0";
 # The height of the control box.

$autostart = "true";
 # Have the midis automatically play (true=yes, false=no)

$loop = "false";
 # Have the song repeat (true=yes, false=no)

$showtitle = "true";
 # Show song title. (true=yes, false=no)

$fntstyle = "Arial";
 # Title Font Style.

$fntsize = "4";
 # Title Font Size.

$fntbold = "true";
 # Is Title Bold? (true=bold, false=plain)

open (GETDATA, "$datafile");
@Data = <GETDATA>;
close GETDATA;

srand(time ^ $$);
$number = rand(@Data);
$line = @Data[$number];

chomp ($line);
($title, $midi) = split(/\|/, $line);

print "Content-type: text/html\n\n";

if ($showtitle =~ /true/i)
{
    print "<font size=\"$fntsize\" face=\"$fntstyle\">";
    if ($fntbold =~ /true/i) {print "<strong>";}
    print "$title";
    if ($fntbold =~ /true/i) {print "</strong>";}
    print "</font>\n";
}

print "<embed src=\"$midi\" width=\"$width\" height=\"$height\" autost
+art=\"$autostart\" loop=\"$loop\"><noembed><bgsound src=\"$midi\" loo
+p=true></noembed></embed>\n";

exit (0);

Comment on midiplayer.pl
Download Code
Re: midiplayer.pl
by cleen (Pilgrim) on Jul 09, 2001 at 01:24 UTC
    since you have $showtitle = "true"; than $showtitle =~ /true/i is an un-needed regex. IMHO you should just do $showtitle eq "true". Same goes for the rest of the scalers with the same attributes.

    You also might want to incorporate CGI.pm into your script so you can edit attributes of your script via url instead of going and editing the program..IE:
    #!/usr/bin/perl use strict; use CGI qw/:standard/; my $c = new CGI; my $datafile = "/full/path/to/playlist.txt"; my $width = $c->param("width") || 0; my $height = $c->param("height") || 0; my $autostart = $c->param("autostart")|| "true"; my $loop = $c->param("loop") || "false"; my $showtitle = $c->param("showtitle")|| "true"; my $fntstyle = $c->param("fntstyle") || "Arial"; my $fntsize = $c->param("fntsize") || 4; my $fntbold = $c->param("fntbold") || "true"; open(GETDATA, "$datafile"); @Data = <GETDATA>; close(GETDATA); srand(time & $$); my $number = rand(@Data); my $line = @Data[$number]; chomp($line); ($title,$midi) = split(/\|/, $line); print header; if ($showtitle eq "true") { print "<font size=\"$fntsize\" face=\"$fntstyle\">"; print "<strong>" if $fntbold eq "true"; print "$title"; print "</strong>" if $fntbold eq "true"; print "</font>\n"; } print "<embed src=\"$midi\" width=\"$width\" height=\"$height\" autost +art=\"$aut ostart\"l +oop=\"$loop\"><noembed><bgsound src=\"$midi\" loop=true></noembed></e +mbed>\n"; exit (0);

    happy coding.
    -Mark

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://94784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2014-08-27 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (248 votes), past polls