|
-
April 9th, 2003, 02:49 AM
#1
Member
Random Wave File
Ok i tryed google and yahoo and a few other places but i cant find what i need. First off i have a few Wave file saved up on my web space, and on my homepage i want them to play randomly in the background. Let me explain say someone comes to my site then they randomly here one of them then if they goto it again another random one will be played instead of the other one they heard. Anyone know where i could find a script/program that would do this for me or better yet anyone know the code off head? Thanks alot...
-
April 9th, 2003, 03:16 AM
#2
Now I just wrote/c&p this so I havent tested it to see if it works but It could give you a clue about how this type of thing should work.
Put this script in your <body>
<script language="JavaScript">
<!--
// Create array to contain the path n filename for the embedded wav file.
//change the "song" to your filename
wav = new Array
wav[1]="song1.wav"
wav[2]="song2.wav"
wav[3]="song3.wav"
wav[4]="song4.wav"
wav[5]="song5.wav"
// Create a random number between 1 and five
random_num = (Math.round((Math.random()*4)+1))
// Write
var MSIE=navigator.userAgent.indexOf("MSIE");
var NETS=navigator.userAgent.indexOf("Netscape");
var OPER=navigator.userAgent.indexOf("Opera");
if((MSIE>-1) || (OPER>-1)) {
document.write("<BGSOUND SRC=" + wav[random_num] + " LOOP=INFINITE>");
} else {
document.write("<EMBED SRC=" + wav[random_num] + "AUTOSTART=TRUE ");
document.write("HIDDEN=true VOLUME=100 LOOP=TRUE>");
}
-->
</script>
Now If you want more than five "random" files to play, just add another wav[6]="song6.wav"
and so on, and change
Math.round((Math.random()*4)+1) to
Math.round((Math.random()*5)+1) and so on
let me know if it works, havent coded javascript in a long while 
...someone comes to my site then they randomly here one of them then if they goto it again another random one will be played instead of the other one they heard.
Now that would involve cookies and thats a whole other story.
.sig - There never was a .sig?
I own a Schneider EuroPC with MS-Dos 3.3 and it works.
-
April 13th, 2003, 08:52 PM
#3
could also be achieved thro flash - and u could have it preload the sound first
v_Ln
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|