Solved

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

Posted on 2004-09-03
7
472 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
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now