i'm creating a music player using windowsmediaplayer - i've got a text box, cmd button and timer that I want to be able to reduce the volume of the player over the number of seconds that are input in the text box, when the button is clicked.
So that if 3 is typed in for example the volume will reduce to zero (and then stop the player) over a 3 second period.
I can't seem to do the math equation to figure this out, and i'm feeling stupid about it.
Si gave you the formulae, but just to ram it home ...
Code:
Reduce to Amt to Amt to
zero in XX reduce reduce
seconds per sec per 1/2 second
========== ============ ================
3 1/3 = .333 1/(3*2) = .1667
6 1/6 = .1667 1/(6*2) = .0833
10 1/10 = .10 1/(10*2) = .05
Spoo
Last edited by Spoo; Jun 15th, 2010 at 12:34 PM.
Reason: added 1/2 sec column
Note, timer object isn't really precise, so any interval below about 1.5 seconds wont work as fast as it should.
EDIT: Didn't refresh. Si and Spoo gave you correct math based on the approach you asked, but the end result of doing it like that will be a very choppy fade. If the interval is two, it will basically lower the volume to half after one second and after another it will completely mute the sound. My method calculates the intervals in which to reduce the volume by the lowest volume increment (assuming it goes from 0 to 100). That will give you a smooth transition over any interval.
Last edited by baja_yu; Jun 15th, 2010 at 12:34 PM.
not there yet though, if I use the below the volume drops far to quickly, about a second or so.
Code:
Private Sub butfade1_Click()
Timer7.Enabled = True
End Sub
Private Sub Timer7_Timer()
Dim s As Integer 's is number of seconds
Dim fadetime As Long
s = txtfade1.Text
fadetime = 1 / (s * 2)
wmp1.settings.volume = fadetime
If wmp1.settings.volume = 0 Then
wmp1.Controls.stop
Timer7.Enabled = False
End If
End Sub