Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Background music script for website

Status
Not open for further replies.
Newbie Spellweaver
Joined
Dec 21, 2008
Messages
42
Reaction score
11
Ok, ive been seeing a few requests for a background music script for their CMS. I did put one into the phoenixms cype but i thought id release it here.

PHP:
<php
if(rand(0,3)==0) { 
echo ' 
<bgsound src="C:\wamp\www\site\sources\bgm\bluesky.mp3" loop="infinite">'; 
} 
elseif(rand(0,2)==0) {  
echo ' 
<bgsound src="C:\wamp\www\site\sources\bgm\amoria.mp3" loop="infinite">'; 
} 
elseif(rand(0,1)==0) { 
echo ' 
<bgsound src="C:\wamp\www\site\sources\bgm\shiningharbor.mp3" loop="infinite">'; 
} else{ 
echo ' 
<bgsound src="C:\wamp\www\site\sources\bgm\upon the sky.mp3" loop="infinite">'; 
}
?>

now you must be thinking, where do i put it?
my advice is to put it into header.php

ok now you have header.php open you need to search for

PHP:
<body>
which is the start of the main part of your website.

once you have found that add the code in above it so it looks like this :


PHP:
<php
if(rand(0,3)==0) { 
echo ' 
<bgsound src="C:\wamp\www\site\sources\bgm\bluesky.mp3" loop="infinite">'; 
} 
elseif(rand(0,2)==0) {  
echo ' 
<bgsound src="C:\wamp\www\site\sources\bgm\amoria.mp3" loop="infinite">'; 
} 
elseif(rand(0,1)==0) { 
echo ' 
<bgsound src="C:\wamp\www\site\sources\bgm\shiningharbor.mp3" loop="infinite">'; 
} else{ 
echo ' 
<bgsound src="C:\wamp\www\site\sources\bgm\upon the sky.mp3" loop="infinite">'; 
}
?>
<body>

now youve done the code you need some music.

as you can see in the code there are file directories pointing to the mp3. Make a folder somewhere in your websites files, put your mp3's inside and change the directories in the script to point to your mp3.

I hope this has helped.
 
may web.very maple.pls.
Loyal Member
Joined
Aug 12, 2009
Messages
1,810
Reaction score
606
Nice work but i rather have a
music player that u can stop or play xD
 
Newbie Spellweaver
Joined
Dec 21, 2008
Messages
42
Reaction score
11
yes i suppose but i thought id release it just in case.

well, suppose its kinda a guide
 
Newbie Spellweaver
Joined
Jun 14, 2008
Messages
19
Reaction score
0
it doesnt work?......nothing happens after i added that....no music at all and there are mp3 files in the bgm folder...im sure of that
 
Last edited:
Infraction Baɴɴed
Loyal Member
Joined
Apr 9, 2008
Messages
1,416
Reaction score
169
1) doesnt work because the link is messed up.
2) the code is ugly

here...
PHP:
<?php
$random = rand(0,3);
if($random == 3) { 
	echo "<bgsound src=\"./sources/bgm/bluesky.mp3\" loop=\"infinite\">"; 
} elseif($random == 2) {  
	echo "<bgsound src=\"./sources/bgm/amoria.mp3\" loop=\"infinite\">"; 
} elseif($random == 1) { 
	echo "<bgsound src=\"./sources/bgm/shiningharbor.mp3\" loop=\"infinite\">"; 
} else { 
	echo "<bgsound src=\"./sources/bgm/upon the sky.mp3\" loop=\"infinite\">"; 
}
?>
 
Last edited:
Newbie Spellweaver
Joined
Jun 14, 2008
Messages
19
Reaction score
0
1) doesnt work because the link is messed up.
2) the code is ugly

here...
PHP:
<?php
$random = rand(0,3);
if($random == 3) { 
	echo "<bgsound src=\"./sources/bgm/bluesky.mp3\" loop=\"infinite\">"; 
} elseif($random == 2) {  
	echo "<bgsound src=\"./sources/bgm/amoria.mp3\" loop=\"infinite\">"; 
} elseif($random == 1) { 
	echo "<bgsound src=\"./sources/bgm/shiningharbor.mp3\" loop=\"infinite\">"; 
} else { 
	echo "<bgsound src=\"./sources/bgm/upon the sky.mp3\" loop=\"infinite\">"; 
}
?>

ok i put that and nothing happens o_O i went to my website's homepage and no music at all......

EDIT: it works but only on internet explorer...not on the other browsers such as chrome and firefox
 
Last edited:
Infraction Baɴɴed
Loyal Member
Joined
Apr 9, 2008
Messages
1,416
Reaction score
169
ok i put that and nothing happens o_O i went to my website's homepage and no music at all......

EDIT: it works but only on internet explorer...not on the other browsers such as chrome and firefox
PHP:
<?php
$random = rand(0,3);
$browser = $_SERVER['HTTP_USER_AGENT'];
if((strpos($browser, "Firefox") !=0) || (strpos($browser, "Chrome") !=0)) {
    if($random == 3) {
        echo "<embed src=\"./sources/bgm/bluesky.mp3\" autostart=\"true\" loop=\"true\" width=\"2\" height=\"0\"></embed>";
    } elseif($random == 2) {
        echo "<embed src=\"./sources/bgm/amoria.mp3\" autostart=\"true\" loop=\"true\" width=\"2\" height=\"0\"></embed>";
    } elseif($random == 1) {
        echo "<embed src=\"./sources/bgm/shiningharbor.mp3\" autostart=\"true\" loop=\"true\" width=\"2\" height=\"0\"></embed>";
    } else {
        echo "<embed src=\"./sources/bgm/upon the sky.mp3\" autostart=\"true\" loop=\"true\" width=\"2\" height=\"0\"></embed>";
    }
} else {
    if($random == 3) {
        echo "<noembed><bgsound src=\"./sources/bgm/bluesky.mp3\" loop=\"infinite\"></noembed>";
    } elseif($random == 2) {
        echo "<noembed><bgsound src=\"./sources/bgm/amoria.mp3\" loop=\"infinite\"></noembed>";
    } elseif($random == 1) {
        echo "<noembed><bgsound src=\"./sources/bgm/shiningharbor.mp3\" loop=\"infinite\"></noembed>";
    } else {
        echo "<noembed><bgsound src=\"./sources/bgm/upon the sky.mp3\" loop=\"infinite\"></noembed>";
    }
}
?>
should work for all firefox, chrome, and iexplorer.exe
 
Newbie Spellweaver
Joined
Jan 24, 2009
Messages
54
Reaction score
0
PHP:
<?php
$random = rand(0,3);
$browser = $_SERVER['HTTP_USER_AGENT'];
if((strpos($browser, "Firefox") !=0) || (strpos($browser, "Chrome") !=0)) {
    if($random == 3) {
        echo "<embed src=\"./sources/bgm/bluesky.mp3\" autostart=\"true\" loop=\"true\" width=\"2\" height=\"0\"></embed>";
    } elseif($random == 2) {
        echo "<embed src=\"./sources/bgm/amoria.mp3\" autostart=\"true\" loop=\"true\" width=\"2\" height=\"0\"></embed>";
    } elseif($random == 1) {
        echo "<embed src=\"./sources/bgm/shiningharbor.mp3\" autostart=\"true\" loop=\"true\" width=\"2\" height=\"0\"></embed>";
    } else {
        echo "<embed src=\"./sources/bgm/upon the sky.mp3\" autostart=\"true\" loop=\"true\" width=\"2\" height=\"0\"></embed>";
    }
} else {
    if($random == 3) {
        echo "<noembed><bgsound src=\"./sources/bgm/bluesky.mp3\" loop=\"infinite\"></noembed>";
    } elseif($random == 2) {
        echo "<noembed><bgsound src=\"./sources/bgm/amoria.mp3\" loop=\"infinite\"></noembed>";
    } elseif($random == 1) {
        echo "<noembed><bgsound src=\"./sources/bgm/shiningharbor.mp3\" loop=\"infinite\"></noembed>";
    } else {
        echo "<noembed><bgsound src=\"./sources/bgm/upon the sky.mp3\" loop=\"infinite\"></noembed>";
    }
}
?>
should work for all firefox, chrome, and iexplorer.exe

Works like a charm ^^
 
Infraction Baɴɴed
Loyal Member
Joined
Apr 9, 2008
Messages
1,416
Reaction score
169
cool bump bro.

smart............................. its for the website SO yes IT will WORK for BUTSAGES cms
 
Custom Title Activated
Loyal Member
Joined
Dec 31, 2004
Messages
4,091
Reaction score
25
your welcome.

this is an example of coding error. you need to develop something that works across many platform.

You are still a crappy programmer.
 
Status
Not open for further replies.
Back
Top