Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

midiplayer.pl

by JSchmitz (Canon)
on Jul 08, 2001 at 04:16 UTC ( [id://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);
Replies are listed 'Best First'.
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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-18 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found