Results 1 to 4 of 4

Thread: Random MIDI background music

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    Random MIDI background music

    What I did:

    <%
    Randomize
    tSong = Int(RND*41) + 1
    strSong = "mdi\" & cstr(tSong) & ".mid" %>
    <bgsound src="<%=strSong%>" loop="-1">


    I guess you see what it does

    Instead, I'd like to have the song play through once only and then randomly start another one.
    Irealize it probably wouldn't still be the bgsound, but maybe a javascript that starts on page load?

    Thanks all.
    Wengang
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Even though I hate when sites use bg sound and user dont have the option to turn the off. I guess you have a good reason. Have fun

    Danial

    VB Code:
    1. <%
    2.     Dim strPlayed
    3.     Dim rndValue
    4.     Dim n
    5.        
    6.     rndValue = GetRandomValue
    7.    
    8.     'these are the songs number that has already been played
    9.    
    10.     'use cookie or session variable to store number of the already played songs
    11.     strPlayed = "1,19,23,32,40"
    12.    
    13.     n = Split(strPlayed, ",")
    14.    
    15.     'No more number to generate
    16.     If UBound(n) >= 40 Then
    17.         strPlayed = ""
    18.         Exit Sub
    19.     End If
    20.    
    21.  
    22.     Do
    23.         rndValue = GetRandomValue
    24.         If Played(rndValue) = False Then
    25.             Exit Do
    26.         End If
    27.     Loop
    28.        
    29.     If strPlayed = "" Then
    30.         strPlayed = rndValue
    31.     Else
    32.         strPlayed = strPlayed & "," & rndValue
    33.     End If
    34.    
    35.     strSong = "mdi\" & CStr(rndValue) & ".mid"
    36.    
    37.  
    38. Function Played(value)
    39.     Dim b
    40.     Dim tmp
    41.     Dim i
    42.    
    43.     tmp = False
    44.    
    45.     b = Split(strPlayed, ",")
    46.    
    47.    
    48.     For i = 0 To UBound(b)
    49.         If CInt(value) = CInt(b(i)) Then
    50.             tmp = True
    51.         End If
    52.     Next
    53.    
    54.     Played = tmp
    55.        
    56. End Function
    57.  
    58. Function GetRandomValue()
    59.     GetRandomValue = Int(Rnd * 41) + 1
    60. End Function
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    Thanks.

    I promise to include a button for turning off the sound.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  4. #4
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by wengang
    Thanks.

    I promise to include a button for turning off the sound.
    Thank you

    Forgot to add the randomize line

    VB Code:
    1. Function GetRandomValue()
    2.     Randomize Timer
    3.     GetRandomValue = Int(Rnd * 41) + 1
    4. End Function

    Note that i have only tested the code in VB and works fine, havent tested it on ASP, let me know if you run inot any problem.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

Posting Permissions

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



Click Here to Expand Forum to Full Width