Solved

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

Posted on 2004-09-03
7
476 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:bignig32
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 11971932

    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")
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11972222
just use PlaySound VB.NET function:

PlaySound(file, 0, SND_FILENAME)
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11972236
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:YZlat
ID: 11972253
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
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11976622
Yeah, you've gotta get those Integers in there, instead of Longs :)

Bob
0
 

Author Comment

by:bignig32
ID: 11980888
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
0
 
LVL 27

Expert Comment

by:planocz
ID: 11995842
sndPlaySound is a API that you use to physically call your sound system.
The OpenWave is just a procedure to read a .wav file.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question