How can I get my program to play a sound when I press a key, or click somewhere? Like:
If keycode = 17 then
'play sound
end if
end sub
Printable View
How can I get my program to play a sound when I press a key, or click somewhere? Like:
If keycode = 17 then
'play sound
end if
end sub
Enter this in a code module:
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Const SND_ASYNC = &H1 ' play asynchronously
and call it fram the form like this:
sndPlaySound soundName, SND_ASYNC
where soundName is a string holding the directory and filename of your wav file...
it depends on what type of sound you want to play if you just want to make a windows beep type in Beep other wise youll have to use the code in the above post unless their are other ways i dont know of.
There is many ways to do a thing, but wav files....my way...beeps...dogfish227s way...would probably be the best for your game...
Yea, i already have sounds added that way, but what i want is some back ground music, and since MP3 is the only kind i have, is there a way to add that, and so the game doesnt actualy stop while its playing?
DirectShow should be able to play MP3 in the background.
direct show?
lol ,
he means Direct Sound
which contains huge api functions giving you full control of the sound card , even its memory .
When I say DirectShow then I mean DirectShow.
DirectSound is not capable of playing MP3s without you writing the decoder. But DirectShow is capable of reading and playing MP3s.
I might also suggest FMod, get your feet wet with professional sound features without going into DirectX :)
www.fmod.org
It can play wave, ogg vorbis, mp3, pcm, etc. and it's free if your app is.