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
Solved

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

Posted on 2004-09-03
7
475 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

765 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