Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A very simple Visual Basic Question about Playing sound

Status
Not open for further replies.

Cndn

Programmer
Nov 22, 2001
22
0
0
CA
I am completly frusterated with the Visual Basic audio code. Those guys at Microsoft made way more complicated than it had to be. I have tried everything to have sound in my project, and the best I could do was have a Midi file that needs to be played manually by the uder (you know, clicking the play ans stop buttons on the little icon). When I tried to use Microsoft Media Control my computer beeped at me and told me I didn't have the authorization or rights or something to use Microsoft Media Control. Will someone please tell me a simple way of playing most of the major types of sound files? All I wanted was a little music!!! I would appreciate if someone could help me out.

Thanks :)
 
paste the following code in a new module and call the 'play' function :


Option Compare Database
Option Explicit

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Const SND_ALIAS = &H10000
'Play a Windows sound (such as SystemStart, Asterisk, etc.).
Const SND_ASYNC = &H1
'Continue program execution immediately after starting to play the sound.
Const SND_FILENAME = &H20000
'Play the specified filename.
Const SND_LOOP = &H8
'Play the sound repeatedly until sndPlaySound is called again with lpszSoundName = "". SND_ASYNC must also
'be set.
Const SND_NODEFAULT = &H2
'Do not play the Windows default sound if the specified sound cannot be found.
Const SND_NOSTOP = &H10
'Do not stop playing any currently playing sounds.
Const SND_NOWAIT = &H2000
'Do not wait if the sound driver is busy.
Const SND_SYNC = &H0

Sub play()

' Play the Empty Recycle Bin system sound and pause
' program execution until the sound is finished playing.
Dim retval As Long

retval = sndPlaySound("c:\winnt\phasers.wav", SND_ASYNC) ' play the associated sound
' Put the path to your sound file here.


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top