Link to home
Start Free TrialLog in
Avatar of bignig32
bignig32

asked on

How to play a WAV file in a VB.net form

HI all,
        I am currently a newbie to VB.net and am currently devloping a program that is an alarm clock.
Now at the moment when the alarm goes off basicly it just opens loads of messageboxses:
messagebox.show ("ALARM!!!!")
However i would like this program to play a WAV File when the alarm goes off.

i am afarid that i have got no idea on how i would do this so please be patient LOL ;-)


matt
ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
just use PlaySound VB.NET function:

PlaySound(file, 0, SND_FILENAME)
Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer

Friend Sub PlayAudio(ByVal FileName As String)

Dim retval As Integer

retval = PlaySound(FileName, 0, 1)

End Sub
Public Sub PlayMySound(ByVal filepath As String)
  Try
    PlaySound(filepath, 0, 1)
  Catch ex As Exception
    Debug.WriteLine("Can't play sound:" & ex.Message)
  End Try
End Sub
Yeah, you've gotta get those Integers in there, instead of Longs :)

Bob
Avatar of bignig32
bignig32

ASKER

Hi all,
i have used this code:
   Public Const SND_SYNC = &H0                     'play synchronously (default)
    Public Const SND_NODEFAULT = &H2                'silence not default, if sound not found
 
  Private Declare Ansi Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long


   Public Sub OpenWave(ByVal sVoicefile As String)
        Dim x As Long
        Dim sPath As String = "MYPATH"    '<-------- Directory of wave files
        x = sndPlaySound(sPath & sVoicefile, SND_SYNC Or SND_NODEFAULT)
    End Sub


Example:      OpenWave("Beback.wav")

and it is working gr8!!! :D:D:D:D:D:D
but i have no idea w2hat i have just done LOL
could some one please explane to me what i have just done???
thanks
Matty
sndPlaySound is a API that you use to physically call your sound system.
The OpenWave is just a procedure to read a .wav file.