Results 1 to 8 of 8

Thread: playing wav files

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    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

  2. #2
    Addicted Member
    Join Date
    Nov 2000
    Location
    State of Confusion
    Posts
    133

    Re: playing wav files

    Got this from MSDN... Works ok for me..
    VB Code:
    1. Public Class SoundClass
    2.         Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
    3.            As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer
    4.         ' name specifies the sound file when the SND_FILENAME flag is set.
    5.         ' hmod specifies an executable file handle.
    6.         ' hmod must be Nothing if the SND_RESOURCE flag is not set.
    7.         ' flags specifies which flags are set.
    8.  
    9.         ' The PlaySound documentation lists all valid flags.
    10.         Public Const SND_SYNC = &H0          ' play synchronously
    11.         Public Const SND_ASYNC = &H1         ' play asynchronously
    12.         Public Const SND_FILENAME = &H20000  ' name is file name
    13.         Public Const SND_RESOURCE = &H40004  ' name is resource name or atom
    14.  
    15.         Public Sub PlaySoundFile(ByVal filename As String)
    16.             ' Plays a sound from filename.
    17.             PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC)
    18.         End Sub
    19.     End Class
    20.  
    21.  
    22.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    23.         Dim SoundInst As New SoundClass
    24.         SoundInst.PlaySoundFile("C:\Soundfile.wav")
    25.     End Sub
    "Don't take life too seriously, you'll never get out alive"
    from Van Wilder

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: playing wav files

    VB Code:
    1. Public Class MM
    2.     Private Declare Auto Function PlaySound Lib "winmm.dll" _
    3.   (ByVal lpszSoundName As String, ByVal hModule As Integer, _
    4.    ByVal dwFlags As Integer) As Integer
    5.  
    6.     Private Const SND_FILENAME As Integer = &H20000
    7.  
    8.     Public Shared Function PlayWav(ByVal fileFullPath As String) As Boolean
    9.  
    10.         Dim iRet As Integer = 0
    11.  
    12.         Try
    13.             iRet = PlaySound(fileFullPath, 0, SND_FILENAME)
    14.         Catch
    15.         End Try
    16.  
    17.         Return iRet <> 0
    18.  
    19.     End Function
    20. End Class

  4. #4
    New Member
    Join Date
    Feb 2005
    Location
    Provo, UT
    Posts
    9

    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.

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: playing wav files

    you would put the code in the form load event instead of the button click event

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: playing wav files

    Quote 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

  8. #8
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: playing wav files

    http://samples.gotdotnet.com/quickst...playsounds.src

    this sample shows how to play an embedded resource wav file.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width