Click to See Complete Forum and Search --> : "Dynamic" Background music


azcn2503
01-26-2003, 06:25 AM
Hey yo!

I'm sort of new here. Well, actually, I am new here.

I have been mucking around a bit, and I decided that I would put some music in to my web page. But what I wanted was for the music to be played when the user enters the page, but they have the choice to stop the music, or select another track from a drop down list.

Say there's three pieces of music in my web space, in the file /sounds/bg/filename.mp3 . I want users to be able to select one of those three pieces of music from a select list, or stop it by pressing either a button or a link.

I can't keep telling the browser to do a document.write("<bgsound src='whatever'>"); so I need to work my way around it. Here's what I have so far...


<head>
<script language="javascript">
var bgSoundSrc=new Array();
bgSoundSrc[1]="/sounds/bg/bg1.mp3";
bgSoundSrc[2]="/sounds/bg/bg2.mp3";
bgSoundSrc[3]="/sounds/bg/bg3.mp3";
function doMusic(aa){
document.write("<bgsound src='" + bgSoundSrc[aa] + "'>");
}
</script>
</head>
<body>
<p>
<form name="soundForm">
Select your music:<br>
<select name="soundSelect" onChange="doMusic(document.soundForm.soundSelect.value);">
<script language="javascript">
for (var soundVar=1;soundVar<=bgSoundSrc.length-1;soundVar++){
document.write("<option value=" + soundVar + ">Track " + soundVar + "<\/option>");
}
</script>
</select>
</form>
</p>
</body>


But if you try selecting a tune, the browser freezes, and it will not let you select another one. So I need some sort of dynamic selection thing. I want to use javascript, and I want to keep it SIMPLE. Remembering I'm only 14 years old and all.

Well, I'll check back regularly. :)

Red~Ice
01-26-2003, 08:05 AM
YEAH IT DOES FREEZE... AND HOW DO YOU GET THE MUSIC TO PLAY. DO YOU PUT THE SONGS IN A FOLDER?