|
-
Feb 8th, 2005, 11:02 AM
#1
Thread Starter
Frenzied Member
playing wav files
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,
Don't anthropomorphize computers -- they hate it
-
Feb 8th, 2005, 11:09 AM
#2
Addicted Member
Re: playing wav files
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
"Don't take life too seriously, you'll never get out alive"
from Van Wilder
-
Feb 8th, 2005, 11:18 AM
#3
Re: playing wav files
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
-
Feb 11th, 2005, 10:18 PM
#4
New Member
Re: playing wav files
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
It is nice to be important, but it is more important to be nice.
-
Feb 12th, 2005, 12:25 AM
#5
Re: playing wav files
you would put the code in the form load event instead of the button click event
-
Feb 12th, 2005, 12:28 AM
#6
Re: playing wav files
Is there a purely .NET way to code it? I notice that the older Win32 API call is used.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 12th, 2005, 01:45 AM
#7
Re: playing wav files
 Originally Posted by RobDog888
Is there a purely .NET way to code it? I notice that the older Win32 API call is used.
no not until 2005
-
Feb 15th, 2005, 05:30 AM
#8
Re: playing wav files
http://samples.gotdotnet.com/quickst...playsounds.src
this sample shows how to play an embedded resource wav file.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|