|
-
Oct 29th, 2009, 07:00 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Looping a .wav File
I can make it loop, but how do I make it Stop. 
Here is my code, this is in a Module
Code:
Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_SYNC = &H0
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H2
Private Const SND_LOOP = &H8
Private Const SND_NOSTOP = &H10
Private Const wFlags = SND_ASYNC Or SND_LOOP
Dim X%
Public Sub Play_LOOP(wavFile as String)
X = sndPlaySound (wavFile , wFlags)
End Sub
Public Sub StopPlay_LOOP(wavFile as String)
X = sndPlaySound( wavFile, SND_ASYNC ) 'wFlags SND_ASYNC
End Sub
The Form
Code:
Option Explicit
Dim myFileName$
Private Sub Form_Load()
myFileName = App.Path & "\tmpClick.wav"
Play_LOOP myFileName
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
StopPlay_LOOP ""
End Sub
Last edited by 5ms?; Oct 29th, 2009 at 10:24 AM.
Reason: Update and Add code
-
Oct 29th, 2009, 07:18 AM
#2
Re: Looping a .wav File
Try
Code:
Public Sub StopPlay_LOOP()
sndPlaySound wavFile , SND_NOSTOP
End Sub
Please mark you thread resolved using the Thread Tools as shown
-
Oct 29th, 2009, 07:49 AM
#3
Thread Starter
Hyperactive Member
Re: Looping a .wav File
Thanks danasegarane, No!, I Tryd "gust now"
sndPlaySound wavFile , SND_NOSTOP
And
sndPlaySound "" , SND_NOSTOP
-
Oct 29th, 2009, 08:40 AM
#4
Re: Looping a .wav File
Here I don't have the movie files.But you are missing the filename in the stop ?
Please mark you thread resolved using the Thread Tools as shown
-
Oct 29th, 2009, 09:23 AM
#5
Thread Starter
Hyperactive Member
Re: Looping a .wav File
Thanks danasegarane, No fix!, wavFile was Global, now it's not.
-
Oct 29th, 2009, 09:31 AM
#6
Re: Looping a .wav File
Nice to see it work.
Refer : How To Play a Waveform (.WAV) Sound File in Visual Basic
Please mark you thread resolved using the Thread Tools
Please mark you thread resolved using the Thread Tools as shown
-
Oct 29th, 2009, 10:08 AM
#7
Thread Starter
Hyperactive Member
Re: Looping a .wav File
It don't work!!
The thread isn't resolved !!
SND_LOOP specifies that the sound will continue to play continuously until sndPlaySound is called again with the lpszSoundName$ parameter set to null. You must also specify the SND_ASYNC flag to loop sounds.
i.e x% = sndPlaySound("",SND_ASYNC)
But it don't Stop
-
Oct 29th, 2009, 10:50 AM
#8
Thread Starter
Hyperactive Member
-
Nov 1st, 2009, 12:41 PM
#9
New Member
Re: Looping a .wav File
 Originally Posted by 5ms?
It don't work
Yes it works!, it works!, it works! 
Make it, and run the exe, and you will see.
-
Nov 1st, 2009, 07:26 PM
#10
Fanatic Member
Re: Looping a .wav File
You replace the "" in this
Code:
Option Explicit
Dim myFileName$
Private Sub Form_Load()
myFileName = App.Path & "\tmpClick.wav"
Play_LOOP myFileName
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
StopPlay_LOOP ""
End Sub
with myFileName, and put this in a modual
Private Sub myFileName()
myFileName = App.Path & "\tmpClick.wav"
End Sub
ps. i got it to work fine. thanks.
-
Nov 2nd, 2009, 10:50 AM
#11
New Member
Re: Looping a .wav File
Can some one till me how to stop the loop at Design time
-
Nov 2nd, 2009, 04:01 PM
#12
Fanatic Member
-
Nov 2nd, 2009, 06:00 PM
#13
New Member
-
Nov 2nd, 2009, 06:08 PM
#14
Re: Looping a .wav File
Design-time only means while you are writing code, etc. Run-time is when you run it, whether that is in VB or compiled.
The answer to your question is that you cannot stop the code and then have something happen - you need to close it properly (the same way you would when it is compiled), so that the code to tidy up has a chance to run.
Note that Form_QueryUnload is actually the wrong place for the code, it should be in Form_Unload instead. There is an explanation of why in the article How should I close my form/program/class? from our Classic VB FAQs
-
Nov 2nd, 2009, 06:21 PM
#15
New Member
Re: Looping a .wav File
si_the_geek
So, if I put the call (StopPlay_LOOP "") in Form_Unload it will Stop Playing the loop when I close the Form?
-
Nov 2nd, 2009, 06:37 PM
#16
Thread Starter
Hyperactive Member
Re: Looping a .wav File
hardLee
No,
I ran this, and it's the same.
Code:
Option Explicit
Dim myFileName$
Private Sub Form_Load()
myFileName = App.Path & "\tmpClick.wav"
Play_LOOP myFileName
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'
End Sub
Private Sub Form_Unload(Cancel As Integer)
StopPlay_LOOP ""
End Sub
But when it is compiled (made in to an .exe) it's ok
.
Last edited by 5ms?; Nov 2nd, 2009 at 06:40 PM.
Reason: But when it is compiled (made in to an .exe) it's ok
-
Nov 2nd, 2009, 06:48 PM
#17
Re: Looping a .wav File
It should stop playing if you close the form, but not if you halt the code (using the "Stop" button on the toolbar, the End or Stop commands, etc).
It does not matter whether it is compiled or not - the only difference that makes is that you can't halt it when it is compiled, so you are forced to close it instead.
-
Nov 2nd, 2009, 07:17 PM
#18
New Member
Re: Looping a .wav File
 Originally Posted by si_the_geek
It should stop playing if you close the form, but not if you halt the code (using the "Stop" button on the toolbar, the End or Stop commands, etc).
It does not matter whether it is compiled or not - the only difference that makes is that you can't halt it when it is compiled, so you are forced to close it instead.
si_the_geek
My brain hurts trying to think how I'm going to fix it.
My code now
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
StopPlay_LOOP ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
StopPlay_LOOP ""
End Sub
I Ran the code it started playing.
I closed the form (by 'Clicking the close button' on the form)the form closed, I was back to vb Design-time, But it did not stop playing.
I made it in to an .exe
Ran the exe and it started playing.
I closed the exe and it stop playing.
 Originally Posted by 5ms?
Here is the zip 
-
Nov 2nd, 2009, 07:20 PM
#19
Fanatic Member
Re: Looping a .wav File
Um, acctualy, i made one that stops by a button. And Yes its in a loop. Ill try to upload it. thats weird.... it wont let me upload it.
-
Nov 2nd, 2009, 07:24 PM
#20
New Member
Re: Looping a .wav File
Is "it" an exe?, you can not upload an exe.
exe are ok for me.
Design-time not ok.
Last edited by hardLee; Nov 2nd, 2009 at 07:28 PM.
-
Nov 3rd, 2009, 05:29 AM
#21
Re: Looping a .wav File
I just tried it, and it doesn't stop - and from a quick read of an earlier post, I can see that it is because you have made a clear mistake.
You got this from the documentation:
 Originally Posted by 5ms?
SND_LOOP specifies that the sound will continue to play continuously until sndPlaySound is called again with the lpszSoundName$ parameter set to null.
..but rather than use a Null string, you used an empty one - and that is completely different (Null means there is no value at all, empty means there is a value with no characters).
Use this instead:
Code:
Public Sub StopPlay_LOOP()
sndPlaySound vbNullString, 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
StopPlay_LOOP
End Sub
...and as I said before, you should not have anything in Form_QueryUnload
-
Nov 3rd, 2009, 09:31 AM
#22
Thread Starter
Hyperactive Member
Re: Looping a .wav File
-
Nov 3rd, 2009, 09:42 AM
#23
Re: Looping a .wav File
The documentation says to use SND_NODEFAULT, so that would be the best idea.
-
Nov 3rd, 2009, 10:15 AM
#24
Thread Starter
Hyperactive Member
Re: Looping a .wav File
Thanks si_the_geek
Dun that, and Updated the zip
 Originally Posted by 5ms?
Here is the zip
Updated the zip.
Now it works properly.
Thanks to si_the_geek, for you help. 
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
|