-
how can i play a wav sound in a vb program.
i am using media player control but that only for win 98.
plus if i put the sound in the same directory as the program (after it's compiled to exe) it can't find them. i didn't sepecify a path to look in. i just wrote the sound name.
i've tried sound recorder control but it didn't work. (some error)
is there a another way to play wave sounds that is compatible with windows 95.
thank you
-
Code:
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Const SND_ASYNC = &H1
Public Const SND_NODEFAULT = &H2
Put the above code in the General Declarations of a module. Then, to play a file, use:
Call sndPlaySound("C:\MyFile.wav", SND_ASYNC Or SND_NODEFAULT)
To stop all wave sounds currently playing, use:
Call sndPlaySound(vbNullString, SND_NODEFAULT)
-
Thank you very much
but will it work if you don't specify a path. (in other words, will it look for the sound in the same directory as the program is, if i don't put a path for it?)
-
If it is in your directory:
Code:
Call sndPlaySound(App.path & "\MyFile.wav", SND_ASYNC Or SND_NODEFAULT)
If it is a different directory:
Code:
Call sndPlaySound("C:\Windows\MyFile.wav", SND_ASYNC Or SND_NODEFAULT)
-
And if the file is not found, I makes the standard Beep sound.