Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-03
7
Medium Priority
?
481 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

715 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