使用PlaySound播放wave檔的四種方式 |
|
aaronka2002
一般會員 發表:6 回覆:15 積分:4 註冊:2002-08-30 發送簡訊給我 |
Make your app speak. - by Borland Developer Support Staff
Technical Information Database TI2846C.txt Make your app speak.
Category :Windows API
Platform :Win95/NT
Product : C Builder1.0 C Builder3.x Description:
This TI demonstrates how to make your CBuilder
application "talk" by loading and playing a wave file
four different ways: 1) Use the PlaySound() function to directly
play a wave file. 2) Read the wave file into memory, then use the
PlaySound() to play the wave file 3) Use PlaySound to directly play a wave
file thats embedded in a resource file attached
to your application. 4) Read a wave file thats embedded in a resource
file attached to your application into memory,
then use the PlaySound() to play the wave file. Reference: To build the project you will need to: 1) Create a wave file called 'mail.wav'
in the project's directory. 2) Create a text file called 'wave.rc'
in the project's directory. 3) Add the following line to the file 'wav.rc':
MAIL WAVE mail.wav 4) Use the project manager to add 'wav.rc' to
to the project. //---------------------------------------------------------------------------
void __fastcall TForm1::FromFileClick(TObject *Sender)
{
PlaySound("mail.wav", NULL, SND_FILENAME);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FromFileMemoryClick(TObject *Sender)
{
TFileStream *WaveFile = new TFileStream("mail.wav", fmOpenRead);
BYTE *wavemem = new BYTE[WaveFile->Size 1]; WaveFile->Read(wavemem, WaveFile->Size); PlaySound(wavemem, NULL, SND_MEMORY); delete[] wavemem;
delete WaveFile;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FromResourceClick(TObject *Sender)
{
PlaySound("MAIL", HInstance, SND_RESOURCE);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FromResourceMemoryClick(TObject *Sender)
{
HANDLE ResHandle;
BYTE *WavData; ResHandle = FindResource(HInstance, "MAIL", "WAVE");
ResHandle = LoadResource(HInstance, ResHandle);
WavData = (unsigned char *)LockResource(ResHandle); PlaySound(WavData, NULL, SND_MEMORY); FreeResource(ResHandle);
}
//--------------------------------------------------------------------------- 12/30/99 aaronks2002註:以上方式若長時間播放,會遇到在播音時,偶爾發生延遲的現象。(win98se)
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |