WEB HTML: Two music files playing randomly in the background.

Discussion in 'OT Technology' started by Roger Rabbi, Nov 14, 2009.

  1. Roger Rabbi

    Roger Rabbi OT Supporter

    Joined:
    Jul 21, 2004
    Messages:
    8,129
    Likes Received:
    0
    Location:
    Socal
    I've looked everywhere for an HTML/Javascript code where only two songs are randomly played in the background of my site without using flash. I've tried editing out codes where more than 2 songs are used, but then it may work for the most part but sometimes when I'd refresh, no music would play at times. This is what I have at the moment, but I don't know what's wrong with it:

    <script type="text/javascript">
    var numberOfSongs = 2
    var sound = new Array(numberOfSongs+1)
    sound[0]= "song1.mp3"
    sound[1]= "song2.mp3"
    function randomNumber(){
    var randomLooper = -1
    while (randomLooper < 0 || randomLooper > numberOfSongs || isNaN(randomLooper)){ randomLooper = parseInt(Math.random()*(numberOfSongs+1))
    }
    return randomLooper
    }
    var randomsub = randomNumber ()
    var soundFile = sound[randomsub]
    if (navigator.appName == "Microsoft Internet Explorer")
    document.writeln ('<BGSOUND SRC="' + soundFile + '" loop=5>');
    else if (navigator.appName == "Netscape")
    document.writeln ('<EMBED SRC= "' + soundFile + '" loop=5 PLAYCOUNT=3 hidden=true autostart=true><P>');
    else if (navigator.appName == "Mozilla")
    document.writeln ('<EMBED SRC= "' + soundFile + '" loop=5 PLAYCOUNT=3 hidden=true autostart=true><P>');
    else if (navigator.appName == "Mozilla Firefox")
    document.writeln ('<EMBED SRC= "' + soundFile + '" loop=5 PLAYCOUNT=3 hidden=true autostart=true><P>');
    </script>

    The two songs may appear at random refresh times, but there are many times where it's just blank. Can anyone find the problem or give a different, simpler code? Thanks.
     
  2. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,329
    Likes Received:
    75
    Location:
    Tasmania
    Untested, and someone better than me probably has a better way, but this should work..

    Call your tracks "song0.mp3" and "song1.mp3"..

    Code:
    <script type="text/javascript"> 
    <!--
    var songNumber = Math.floor(Math.random()*2);
    var playSong = "song" + songNumber + ".mp3";
    
    if (navigator.appName == "Microsoft Internet Explorer") 
    document.writeln ('<BGSOUND SRC="' + playSong + '" loop=5>'); 
    else if (navigator.appName == "Netscape") 
    document.writeln ('<EMBED SRC= "' + playSong + '" loop=5 PLAYCOUNT=3 hidden=true autostart=true><P>'); 
    else if (navigator.appName == "Mozilla") 
    document.writeln ('<EMBED SRC= "' + playSong + '" loop=5 PLAYCOUNT=3 hidden=true autostart=true><P>'); 
    else if (navigator.appName == "Mozilla Firefox") 
    document.writeln ('<EMBED SRC= "' + playSong + '" loop=5 PLAYCOUNT=3 hidden=true autostart=true><P>'); 
    // -->
    </script> 
    
     
  3. hsmith

    hsmith OT Supporter

    Joined:
    Feb 24, 2002
    Messages:
    124,562
    Likes Received:
    650
    Location:
    Your mother.
    you are aware geocities has been shut down, right?
     
  4. whomadewho

    whomadewho Ohhh FCN Ohhhhh FCN!

    Joined:
    Jan 10, 2002
    Messages:
    20,235
    Likes Received:
    0
    Location:
    San Francisco
    this is probably the single most annoying thing on a website. Want me to link you to a good site to download Toto_africa.mid?
     
  5. BlazinBlazer Guy

    BlazinBlazer Guy Witness to The De-Evolution of Mankind.

    Joined:
    Jul 24, 2002
    Messages:
    18,783
    Likes Received:
    0
    Location:
    Lansing, MI USA
    :rofl::rofl::rofl::rofl:
     
  6. Roger Rabbi

    Roger Rabbi OT Supporter

    Joined:
    Jul 21, 2004
    Messages:
    8,129
    Likes Received:
    0
    Location:
    Socal
    I have a domain, you n-word.
     
  7. Roger Rabbi

    Roger Rabbi OT Supporter

    Joined:
    Jul 21, 2004
    Messages:
    8,129
    Likes Received:
    0
    Location:
    Socal
    Thanks! I'll try it out.
     
  8. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,329
    Likes Received:
    75
    Location:
    Tasmania
    As much as i'm trying to be helpful with the code, I highly recommend AGAINST embedding music.. if you /have/ to, do it with flash and include an easy and prominent way to disable it.
     

Share This Page