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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a .wav as embedded resource?

Status
Not open for further replies.

Sypher2

Programmer
Joined
Oct 3, 2001
Messages
160
Location
US
I'm using the old PlaySound API to play some mouseover and button click .wavs.

Currently the .wavs are in a folder on the server which is referenced by the app's config file. There is occassionally some lag time between the button click and when the .wav is actually played (due to network latency).

I was hoping to embed the .wavs in the app, but I can't seem to figure out how to write code to play the embedded .wav.

Is there any way to reference an embedded .wav?
 
Well first of all make sure you've got the wav file in the installation directory you wish to use it in. Then to reference the wav file you'll need the lines of code below.

Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long 'this line will declare the function sndPlaySound which you can use in your app to play any media file it supports. You will want to declare this function at the top of the form or in a module.

To call the function use a line like this:
sndPlaySound(strFullPath & "\wowman.wav", 1)
' strFullPath is the location of the folder you wish to play the wav file from
' The "\wowman.wav" is just an example of the filename you will need to replace

FYI - You can use this line of code to determine the installation location of the files you wish to access. It is used in the above example.

Public strFullPath As String = System.IO.Path.GetDirectoryName((System.Reflection.Assembly.GetExecutingAssembly.Location))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top