Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Stream MP3 in the background

As a newbee,
I am looking for a way to stream background sound in my website.
I have 10 different themes, currently in MP3.

1. A theme would be chosen randomly and played in the background.
2. Each sound file is like 3MB and therefore better not force the users to download all of them
   in advance.
3. I would like to give the user the ability to change the background music.
0
peledc
Asked:
peledc
1 Solution
 
Squew01Commented:
Add this script just after the <HEAD> tag

<script language="javascript">

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};

function rand(number) {
        return Math.ceil(rnd()*number);
};

function music()
{
music[0]="mymusic0.mp3"; // Don't forget to change the name
music[1]="mymusic1.mp3";
music[2]="mymusic2.mp3";
music[3]="mymusic3.mp3";
music[4]="mymusic4.mp3";
music[5]="mymusic5.mp3";
music[6]="mymusic6.mp3";
music[7]="mymusic7.mp3";
music[8]="mymusic8.mp3";
music[9]="mymusic9.mp3";

i=rand(9);

if (navigator.appName.indexOf("Microsoft") != -1){        
document.write('<BGSOUND SRC="'+ music[i] +'"> ')    
   }
else if (navigator.appName.indexOf("Netscape") != -1){
document.write('<EMBED SRC="'+ music[i] +'" HIDDEN=TRUE AUTOSTART=TRUE> ')
   }
}
</script>

Add this code after tha <BODY> tag

<script>music();</script>

To change the played song, use this link <A href="#">Another Song</a>

Don't forget to change mymusic0.mp3, mymusic1.mp3, ...

/squew/
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now