Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 29,538 times

Related Categories

Play a WAV file

The code below shows you how to play a WAV sound file (with the extension wav)

Public Declare Function playa Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Public Sub PlayWav(sFile As String)
    If Dir(sFile$) <> "" Then Call playa(sFile, SND_FLAG)
End Sub

So, to play a file using this code, enter the following:

'// plays C:\west.wav
Call PlayWav("C:\west.wav")

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Haha, funny side effect

    Posted by HyperHacker on 04 Aug 2003

    I tried it, and it won't stop... VB itself keeps playing the file until I close it. :D What you can do to stop it is [i]Call PlayWav(vbnullstring)[/i] - playing a nonexistant file will stop any curren...

  • SND_FLAG

    Posted by Blobby66 on 27 Jan 2003

    Private Const SND_FLAG = &H1 Or &H2

  • Re: Got an Error

    Posted by todiverge on 10 Jan 2003

    Values for the SND_FLAG variable are defined in the MMSYSTEM.H file (found in the C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include folder on my machine.)

    The following variable...

  • Got an Error

    Posted by Niecole on 04 Nov 2002

    SND_FLAG

    this Variable is not defined it says....Now What?