Hey,
How can I play a wave file in vb.net?
I don't want any external player showing up. It can be used, but I don't want it showing up.
Thanks,
Printable View
Hey,
How can I play a wave file in vb.net?
I don't want any external player showing up. It can be used, but I don't want it showing up.
Thanks,
Got this from MSDN... Works ok for me..
VB Code:
Public Class SoundClass Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _ As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer ' name specifies the sound file when the SND_FILENAME flag is set. ' hmod specifies an executable file handle. ' hmod must be Nothing if the SND_RESOURCE flag is not set. ' flags specifies which flags are set. ' The PlaySound documentation lists all valid flags. Public Const SND_SYNC = &H0 ' play synchronously Public Const SND_ASYNC = &H1 ' play asynchronously Public Const SND_FILENAME = &H20000 ' name is file name Public Const SND_RESOURCE = &H40004 ' name is resource name or atom Public Sub PlaySoundFile(ByVal filename As String) ' Plays a sound from filename. PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC) End Sub End Class Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim SoundInst As New SoundClass SoundInst.PlaySoundFile("C:\Soundfile.wav") End Sub
VB Code:
Public Class MM Private Declare Auto Function PlaySound Lib "winmm.dll" _ (ByVal lpszSoundName As String, ByVal hModule As Integer, _ ByVal dwFlags As Integer) As Integer Private Const SND_FILENAME As Integer = &H20000 Public Shared Function PlayWav(ByVal fileFullPath As String) As Boolean Dim iRet As Integer = 0 Try iRet = PlaySound(fileFullPath, 0, SND_FILENAME) Catch End Try Return iRet <> 0 End Function End Class
Hi, I'm new to the forums. I was just wondering, is there any way to play a wav on a form load? I already know how to do it for a button click.
Any help would be appreciated.
Thanks
you would put the code in the form load event instead of the button click event
Is there a purely .NET way to code it? I notice that the older Win32 API call is used.
no not until 2005Quote:
Originally Posted by RobDog888
http://samples.gotdotnet.com/quickst...playsounds.src
this sample shows how to play an embedded resource wav file.