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

x
?
Solved

background sound in a vb program

Posted on 2000-05-10
11
Medium Priority
?
211 Views
Last Modified: 2008-02-01
how do i get a sound to play in aloop while other activites are going on in a vb app?
0
Comment
Question by:gerrymcd
[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
11 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 150 total points
ID: 2797049
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

To Use:

PlaySound sFile, 0, SND_NODEFAULT Or SND_FILENAME Or SND_ASYNC Or SND_LOOP


where sFile is the full path to the file you want to play



0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2797055
here are the constants declarations:

Private Const SND_NODEFAULT = &H2        
Private Const SND_FILENAME = &H20000    
Private Const SND_ASYNC = &H1        
Private Const SND_LOOP = &H8        
0
 
LVL 18

Expert Comment

by:mdougan
ID: 2797139
If you wanted to play the sound while other things are going on in the program, then you either have to create a Thread, and have the thread call the PlaySound function listed above, or, you can have a timer on the form, and when you set the Timer's enabled property, then in the Timer Event, you'll first set the Enabled property of the timer to false, then call the PlaySound function, then set the Enabled property back to true (so it will play the sound again).

In VB 5 you could use the CreateThread API to create a thread, but Microsoft has provided less support for CreateThread under VB 6, so, the same code may or may not work for you.  I have a sample thread progam I can send if you post an e-mail address.

0
Technology Partners: 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 28

Expert Comment

by:AzraSound
ID: 2797160
the snd_async and snd_loop constants take care of everything
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2797225
here are the definitions of the constants being used:

SND_FILENAME
The pszSound parameter is a filename

SND_NODEFAULT
No default sound event is used. If the sound cannot be found, PlaySound returns silently without playing the default sound

SND_LOOP
The sound plays repeatedly until PlaySound is called again with the pszSound parameter set to NULL. You must also specify the SND_ASYNC flag to indicate an asynchronous sound event

SND_ASYNC
The sound is played asynchronously and PlaySound returns immediately after beginning the sound. To terminate an asynchronously played waveform sound, call PlaySound with pszSound set to NULL






0
 
LVL 4

Expert Comment

by:PBuck
ID: 2797419
First of all AzraSound, you make me sick with all your wonderful website links in pratically all the questions here :-)  How do ou manage all the links?

Secondly, this is a great answer.  I was using something similar (but it wasn't looped)

Now, can you give a sample of a statment to stop the asynchronously played sound?  What do you mean,"call PlaySound with pszSound set to NULL"

Thanks in advance!  AzraSound

Thank-you gerrymcd for letting me eves-drop.







0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2797449
the pszSound referred to is from the msdn help where all references are to the C syntax...it is actually referring to the lpszName in the VB declaration of the api call..so pass vbNullString to the function to stop the sound
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2797566
as for my plethora of links...   =)
being a self-taught vb-er, i found all my resources on the web, so i have a pretty hefty favorites folder full of all the links that i've found useful in the past while learning the language...its pretty amazing how much stuff is out there...
0
 
LVL 4

Expert Comment

by:PBuck
ID: 2797591
I agree with the amount of information out there.  I have started a small but useful favorites folder - but some of the links you post I would not have found.

Thanks for the sound function (and how to stop it).

I am sure I will see you again soon!

gerrymcd - sorry for cluttering your question page.
0
 
LVL 2

Author Comment

by:gerrymcd
ID: 2805717
how do u keep this sound going while another one plays?

ur a guru at sound in vb nice one again!
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2805918
that is not so simple...i would send you a sample project but you gave me a 'B'   =oP   j/k
0

Featured Post

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.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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