Random Wave File
Results 1 to 3 of 3

Thread: Random Wave File

  1. #1
    Member
    Join Date
    Feb 2003
    Posts
    50

    Question 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...
    Hacker dan

  2. #2
    Senior Member
    Join Date
    Mar 2003
    Posts
    117
    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.

  3. #3
    Flash M0nkey
    Join Date
    Sep 2001
    Posts
    3,447
    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
  •