11-19-2001, 11:49 PM
How do you make it so that when ever a function is called such as cmd1_click, VB will play a *.wav file?
And another question: How can you make ambient form music?
Some code examples would be preferred, along with an explanation. Thanks!!
11-19-2001, 11:56 PM
There are many different ways to play .wav files. I would suggest you use the sndPlaySound API call, it seems to work quite well for me. When you say ambient, I'm assuming you mean something "visual", rather than just auditury. (Despite the fact Ambient means "surrounding, encircling") I don't really know, although I assume you there's a way to detect changes in the pitch and draw a line according to a particular pitch.
11-20-2001, 09:48 PM
I have been having problems playing sounds...for example when i load a page[form] a background music should play but it takes a long time to load the song[.wav] and when it does play it plays until the music ends before loading the actual form. I called the function under Form load.
11-20-2001, 10:02 PM
maybe u could use DirectSound, there are lots of examples in this forum, and the best is by squirm, just click on this link, http://www.visualbasicforum.com/bbs/showflat.php?Cat=&Board=tu&Number=59124&page=0&view=collapsed&sb=5&o=& fpart=
11-21-2001, 07:41 AM
Thanks wild wolf.
On the contrary, I also believe that the PlaySound API is the way you need to go. You can set various flags to make it play asynchronously, which means that the form can carry on loading while the sound plays.
<pre>Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long</pre>
^^ These are the constants and the required declare, place at the top of your form's code area. Then, to actually play a sound, you might use this:
<pre>PlaySound "C:\mysound.wav", 0, SND_ASYNC Or SND_FILENAME</pre>
This would play mysound.wav asynchronously, which means the program will carry on running while it plays. For more info on the PlaySound API, look at PlaySound (VBAPI) (http://www.vbapi.com/ref/p/playsound.html)
Happy coding....... images/icons/smile.gif
11-21-2001, 01:11 PM
does this work with VB6???
11-21-2001, 01:15 PM
can you play more than one *.wav file simultaneously?
ie background music and sound effects
11-22-2001, 07:08 AM
no need to thank squirm. quality work has to be appreciated images/icons/smile.gif
yeah it does work with VB6, i had a look at it also and i searched for it in MSDN library, u can also get enough help from there
11-22-2001, 07:20 AM
VB6 - yes.
Multiple wav files - I think its possible with the SND_NOWAIT or maybe the SND_NOSTOP flags but Im not sure.
For a looping sound, such as ambient sound or music, you could use the SND_LOOP flag, and then use the SND_PURGE flag to stop the sound again. You might also want to use SND_NODEFAULT because otherwise if your file doesnt exist, Windows will instead play the 'ding' error sound, which you probably dont want.
As before, to get more info, visit the link I posted above to VBAPI.