Playing wave file in VB.NET

  • Thread starter Thread starter viresh
  • Start date Start date
You need to do this:

Public Const SND_SYNC As Int32 = &H0
Public Const SND_ASYNC As Int32 = &H1
Public Const SND_FILENAME As Int32 = &H20000
Public Const SND_MEMORY As Int32 = &H4


Public Declare Auto Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpSound As IntPtr, ByVal hModule As IntPtr, ByVal dwFlags As Long) As
Long

Public Sub PlaySound()

try
Dim ptrAudio As IntPtr = IntPtr.Zero

' Marshal the sound into an intptr
ptrAudio = Marshal.AllocHGlobal(m_Sound.Length())
Marshal.Copy(m_Sound, 0, ptrAudio, m_Sound.Length())

PlaySound(ptrAudio, IntPtr.Zero, SND_MEMORY Or SND_ASYNC)
catch ex as Exception

finally

If Not ptrAudio.Equals(IntPtr.Zero) Then
Marshal.FreeHGlobal(ptrAudio)
End If
end try
End Sub
 
Back
Top