www.webdeveloper.com
Results 1 to 5 of 5

Thread: Background Music

Hybrid View

  1. #1
    Join Date
    Dec 2002
    Location
    US
    Posts
    7

    Background Music

    Hello,

    I would like to know, how can I make my website to have more than 1 background music(3). As example, when visitors visit my site, the first music will be played. But, when they click refresh, the second music will be played. When refresh is clicked again, the third music will be played.

    Before this, I had came across a website with this feature. So, I would like to know how this thing is done.

    Thank You.

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    It sounds like you are looking for a random sound player? If so (ie. random is ok, rather than it actually playing sound 1, sound 2, sound 3) then this code should work for you.

    Code:
    <body>
    <script language="javascript" type="text/javascript">
    <!--hide 
    
    for (i=0; i<100; i++)
    {
    var x = Math.random()*3
    
    var sound1="song1.mid"
    var sound2="song2.mid"
    var sound3="song3.mid"
    
    if(x<=1)var sound=sound1
    else if(x<=2)var sound=sound2
    else var sound=sound3
    
    document.write('<bgsound src='+'"'+sound+'"'+'loop="false">')
    
    }
    //END hide-->
    </script>
    </body>

  3. #3
    Join Date
    Dec 2002
    Location
    US
    Posts
    7
    Hello

    No, I mean that the background songs will keep on changing. As example, when I go to www.xyz.com, the song1.mid will be played. But, when I go to www.xyz.com again, song2 will be played.


    Go to this Malaysian site, and you will understand what I mean.
    http://special.time.net.my/aidilfitri/

    Thank You.

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Ok, I took a look at the site you pointed me to and from what it sounds like, they use some sort of random song generator, like the one I gave above... Did you try that? Each time you reload your page, it will randomly choose which of the songs you get.

  5. #5
    Join Date
    Dec 2002
    Location
    US
    Posts
    7
    Hello,

    I have tried out the scripts which you have given to me. Quite good. Thank you for helping me.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles