how can i play wav file soound from vb.
Printable View
how can i play wav file soound from vb.
Use the PlaySound API. Make a Form with a CommandButton and put the following code into it.
Code:Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Sub Command1_Click()
'Play the WAV
PlaySound "C:\MyFile.wav", 0&, &H1
End Sub
You can use the microsoft multimedia control
OCX in your componets list
Code:
' bas module code
'API Function to play the sound
'
Public Declare Function sndPlaySound Lib "winmm" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
'
' play synchronously (default)
Public Const SND_SYNC = &H0
' play asynchronously
Public Const SND_ASYNC = &H1
' loop the sound until next
Public Const SND_LOOP = &H8
'form code
Private Sub Command1_Click()
Call sndPlaySound(ByVal "c:\yourfolder\yourfile.wav", SND_ASYNC)
End Sub
Private Sub Command2_Click()
Call sndPlaySound(0,0)
End Sub