|
-
Jan 2nd, 2004, 10:23 AM
#1
Thread Starter
Frenzied Member
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
-
Jan 5th, 2004, 08:44 PM
#2
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:
<%
Dim strPlayed
Dim rndValue
Dim n
rndValue = GetRandomValue
'these are the songs number that has already been played
'use cookie or session variable to store number of the already played songs
strPlayed = "1,19,23,32,40"
n = Split(strPlayed, ",")
'No more number to generate
If UBound(n) >= 40 Then
strPlayed = ""
Exit Sub
End If
Do
rndValue = GetRandomValue
If Played(rndValue) = False Then
Exit Do
End If
Loop
If strPlayed = "" Then
strPlayed = rndValue
Else
strPlayed = strPlayed & "," & rndValue
End If
strSong = "mdi\" & CStr(rndValue) & ".mid"
Function Played(value)
Dim b
Dim tmp
Dim i
tmp = False
b = Split(strPlayed, ",")
For i = 0 To UBound(b)
If CInt(value) = CInt(b(i)) Then
tmp = True
End If
Next
Played = tmp
End Function
Function GetRandomValue()
GetRandomValue = Int(Rnd * 41) + 1
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 : 
-
Jan 5th, 2004, 09:09 PM
#3
Thread Starter
Frenzied Member
Thanks.
I promise to include a button for turning off the sound.
Wen Gang, Programmer
VB6, QB, HTML, ASP, VBScript, Visual C++, Java
-
Jan 5th, 2004, 09:16 PM
#4
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:
Function GetRandomValue()
Randomize Timer
GetRandomValue = Int(Rnd * 41) + 1
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|