devxlogo

How do I add sound to my app?

How do I add sound to my app?

Question:
I have searched high and low and cannot seem to find a code example of how to add sound (attach a WAV file) to the opening of my application.

Answer:
You can use the following code:

Declare the following API calls:Function boolean sndPlaySoundA( & string SoundName, uint Flags ) Library "WINMM"Function uint waveOutGetNumDevs() Library "WINMM"

You can play a sound with the following code:

uint lui_NumDe vslui_NumDevs = WaveOutGetNumDevs()IF lui_NewDevs > 0 THEN  sndPlaySound( "filename.wav", modeofplay(INT) )END IFwhere: modeofplay0 - play synchronously1 - play asynchronously2 - don't use default sound if u can't find file3 - 1&28 - loop the sound until next sndPlaysound10- don't stop any correctly playing sound
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist