How Do You Get Your Project To Play A Sound.... For Instance Lets Say I Did This
Code:Private Sub Form_MouseUp(Button As Integer, Shift As Integer)
'I Want The Sound To Play Here
End Sub
thanks in advanced
Printable View
How Do You Get Your Project To Play A Sound.... For Instance Lets Say I Did This
Code:Private Sub Form_MouseUp(Button As Integer, Shift As Integer)
'I Want The Sound To Play Here
End Sub
thanks in advanced
theres always the multimedia control (add-ins) or u can use directX, which i have no idea how to.
Try something like this:
VB Code:
Option Explicit 'API Declarations #If Win32 Then '32-Bit windows Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _ (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long 'The API that lets sound be played #Else 'Other Windows Public Declare Function sndPlaySound Lib "MMSYSTEM.DLL" _ (ByVal lpszSoundName As Any, ByVal wFlags As Integer) As Integer 'The API that lets sound be played #End If 'API Constants Used for flags in Play Sound function Public Enum SoundFlags SND_LOOP = &H8 ' Loop the sound until next sndPlaySound SND_ALIAS = &H10000 ' Name is a WIN.INI [sounds] entry SND_ALIAS_ID = &H110000 ' Name is a WIN.INI [sounds] entry identifier SND_ALIAS_START = 0 ' Must be > 4096 to keep strings in same section of resource file SND_APPLICATION = &H80 ' Look for application specific association SND_ASYNC = &H1 ' Play asynchronously SND_FILENAME = &H20000 ' Name is a file name SND_MEMORY = &H4 ' lpszSoundName points to a memory file SND_NODEFAULT = &H2 ' Silence not default, if sound not found SND_NOSTOP = &H10 ' Don't stop any currently playing sound SND_NOWAIT = &H2000 ' Don't wait if the driver is busy SND_PURGE = &H40 ' Purge non-static events for task SND_RESERVED = &HFF000000 ' In particular these flags are reserved SND_RESOURCE = &H40004 ' Name is a resource name or atom SND_SYNC = &H0 ' Play synchronously (default) SND_TYPE_MASK = &H170007 SND_VALID = &H1F ' Valid flags / ;Internal / SND_VALIDFLAGS = &H17201F ' Set of valid flag bits. Anything outside End Enum Private Sub PlaySound(ByVal FileName As String, _ Optional Flags As SoundFlags = SND_FILENAME Or SND_NOSTOP) On Error Resume Next 'Goto next line on an error 'If the filename is not "" then play the sound If FileName <> "" Then Call sndPlaySound(FileName, Flags) End Sub
I got it to play sound... but it stops everything in the program until it is done playing... What fixes that?
I haven't done this for years and I believe I did it a different way but if you look at the flags setting it to asynchronus should work...
Can't say for sure I always use DirectSound
I think I've tried that, but I'm not sure I've done it right.
PlaySound ("filename"), (SND_SYNC)
Is that right? If so, it still freezes while it plays a sound.
Use the SND_ASYNC (Asynchronous) flag to allow execution while the sound plays.
Hmm... it works now.. even though I already tried it and it didnt:( Oh well...
Yeah sorry about that, the default flags should have had "Or SND_ASYNC" there too.
hi,
can you see the Attach file the example make your soulve it.
I couldn't be bothered to put my speakers on to test it, but do you need to specify the absolute path, not just "sound_1.wav"? Something like App.Path & "\Sound_1.wav". I've never use the multimedia control, so I'm not sure.