isnoend2001
asked on
stop sound the number of seconds entered in a textbox
I want to play a sound and run a sub(StopSound) after the number of seconds entered into a text box(txtSoundLength)
How ?
How ?
ASKER
Didn't know you could play sounds like that
The sound is in a resource file i don't need the code to play the sound. just need code to play it for the length in the texbox:
This does not work:
Private Sub PlaySound()
sndData = LoadResData("SIREN", "SOUND")
sndPlaySound sndData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY'play the sound
mSoundLength = Val(txtSoundLength) 'how long to play sound
Timer2.Interval = 60000 'one minute
Timer2.Enabled = True
If Now >= mSoundLength Then
StopSound
Timer2.Enabled = False
End If
End Sub
it goes directly to StopSound. Why ?
The sound is in a resource file i don't need the code to play the sound. just need code to play it for the length in the texbox:
This does not work:
Private Sub PlaySound()
sndData = LoadResData("SIREN", "SOUND")
sndPlaySound sndData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY'play the sound
mSoundLength = Val(txtSoundLength) 'how long to play sound
Timer2.Interval = 60000 'one minute
Timer2.Enabled = True
If Now >= mSoundLength Then
StopSound
Timer2.Enabled = False
End If
End Sub
it goes directly to StopSound. Why ?
Unfortunately I have no VB6 on me current computer.
What you need to do is start sound in one method, e.g., when you type a number or click a button and stop it to another method, in timer handler, when you have a tick after required period.
In VB.Net it woud look like:
What you need to do is start sound in one method, e.g., when you type a number or click a button and stop it to another method, in timer handler, when you have a tick after required period.
In VB.Net it woud look like:
Private timlength As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
timlength = CInt(TextBox1.Text) '' convert text to a number
PlaySound()
End Sub
Private Sub PlaySound()
Me.Timer1.Interval = timlength * 1000
My.Computer.Audio.Play("C:\temp\Police.wav", AudioPlayMode.Background)
Me.Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' StopSound()
My.Computer.Audio.Stop()
End Sub
ASKER
i have code to start and stop the sound:
Private Sub PlaySound()
sndData = LoadResData("SIREN", "SOUND")
sndPlaySound sndData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY
Sub StopSound()
sndPlaySound ByVal 0, 0 'stop sound
End Sub
just want the timer to run the sub StopSound it after the seconds in a textbox
Private Sub PlaySound()
sndData = LoadResData("SIREN", "SOUND")
sndPlaySound sndData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY
Sub StopSound()
sndPlaySound ByVal 0, 0 'stop sound
End Sub
just want the timer to run the sub StopSound it after the seconds in a textbox
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Private Sub PlaySound()
sndData = LoadResData("SIREN", "SOUND")
sndPlaySound sndData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY
Timer1.Interval = CLng(Text1.Text) * 1000
Timer1.Enabled = True
End Sub
Sub StopSound()
sndPlaySound ByVal 0, 0 'stop sound
Timer1.Enabled = True
End Sub
I got it
Private Sub Timer1_Timer()
StopSound
Timer1.Enabled = False
End Sub
Private Sub Command1_Click()
PlaySound
End Sub
sndData = LoadResData("SIREN", "SOUND")
sndPlaySound sndData(0), SND_LOOP Or SND_ASYNC Or SND_MEMORY
Timer1.Interval = CLng(Text1.Text) * 1000
Timer1.Enabled = True
End Sub
Sub StopSound()
sndPlaySound ByVal 0, 0 'stop sound
Timer1.Enabled = True
End Sub
I got it
Private Sub Timer1_Timer()
StopSound
Timer1.Enabled = False
End Sub
Private Sub Command1_Click()
PlaySound
End Sub
That's it! :)
1. Create text box lost focus event handler (or (text) change, may be)
2. Put his code into handler
My.Computer.Audio.Play("C:
3. Start timer
4. After timer elapses N seconds where N is a number from text box - call:
My.Computer.Audio.Stop()