Play Wav resource
Posted
by Anthony Petruso
on November 14th, 1998
Parts of this code I ripped from VC++ 4.1 help, but it was outdated and didn't come close to working.
First of all you need to add the wave files to the .rc file manually like so:
<NameOfSound> WAVE <Location of WAVE.>Example being
Cool WAVE C:\projects\sounds\cool.wav
Then you need to add this function declarion to the class you plan on using..
BOOL PlayResource(LPSTR lpName)
{
BOOL bRtn;
LPSTR lpRes;
HANDLE hRes;
HRSRC hResInfo;
HINSTANCE Nl=AfxGetInstanceHandle();
/* Find the WAVE resource. */
hResInfo= FindResource(Nl,lpName,"WAVE");
if(hResInfo == NULL)
return FALSE;
/* Load the WAVE resource. */
hRes = LoadResource(Nl,hResInfo);
if (hRes == NULL)
return FALSE;
/* Lock the WAVE resource and play it. */
lpRes=(LPSTR)LockResource(hRes);
if(lpRes==NULL)
return FALSE;
bRtn = sndPlaySound(lpRes, SND_MEMORY | SND_SYNC);
if(bRtn == NULL)
return FALSE;
/* Free the WAVE resource and return success or failure. */
FreeResource(hRes);
return TRUE;
}
Then to play the sound you simply use:
PlayResource("<soundname>");
Example being
PlayResource("Cool");

Comments
How to play *.wav when we store it on database
Posted by Legacy on 01/20/2004 12:00amOriginally posted by: romi nur ismanto
How to play *.wav when we store it on database
ReplyPlease give me code to play *.wav when thats file is in the database (acces)
How can I pause a long wav file and then resume it?
Posted by Legacy on 10/22/2003 12:00amOriginally posted by: Wenjun
I am using PlaySound() to play wav files. However, I did not find the command to pause and resume the playing. Your kind help is highly appreciated.
ReplyAudio Player Drag and Drop
Posted by Legacy on 05/13/2003 12:00amOriginally posted by: Tapas
ReplyResource putting automation
Posted by Legacy on 05/07/2003 12:00amOriginally posted by: CallMan
Tell me please - how can i write into the resource file a prety big
amount of WAV's ? I do not want to make it manually (Menu -> Insert
->Resource, etc. )
Can i in some way automatise this job ?
Reply
How to play wav on internet ..... Data Streaming
Posted by Legacy on 12/02/2002 12:00amOriginally posted by: Maggie
How to perform Data Streaming on the web page????
-
Replytry this to play a wav file
Posted by ellav on 03/31/2006 09:17amPersonally liked the way of Waveform Audio Interface: in just 2 lines you can play a file in PCM as wav file in c# for compact framework 1.0 VS .NET 2003: //Play a filname.wav WaveOut wo = new WaveOut(); wo.Play(filename, 512*1024, 0xffff, 0xffff); //Thats all thanks o the P/Invoke Library Sample available a MSDN help
ReplyHow do you put a background sound in a form in Visual Basic 6
Posted by Legacy on 11/25/2002 12:00amOriginally posted by: Thomas Hair
How do you put a background sound in a form in Visual Basic 6. I really need to know this for a project that I am making. The audio file is a MP3 file 9is this possible to use as a background sound or does it have to be a WAVE file?)
ReplyHow tp play from buffer?
Posted by Legacy on 08/06/2002 12:00amOriginally posted by: Anurag
How would you play the sound streaming in to a buffer? (not a file.. just a buffer..)
ReplyWave Streams
Posted by Legacy on 07/28/2002 12:00amOriginally posted by: gsc
Are wave streams for playing multiple wave files simultaneosly? If not, how is this done. I believe it is possible to do this using wave channels, or something, but I am have no idea how. If anyone knows, please help me out by explaining this in your reply. Thanks.
Reply
Do it the easy way
Posted by Legacy on 07/16/2002 12:00amOriginally posted by: sanpee
Would it be easier if you just say
ReplyPlaySound(MAKEINTRESOURCE(ID...),hModule,SND_RESOURCE|SND_ASYNC);
How to get the total time of a wav file?
Posted by Legacy on 06/24/2002 12:00amOriginally posted by: jokerhe
Thanks.
ReplyLoading, Please Wait ...