if(m_WaveLong<0) { MessageBox("Failed to read the data chunk"); return; }
//检查音频设备,返回音频输出设备的性能 if(waveOutGetDevCaps(WAVE_MAPPER,&pwoc,sizeof(WAVEOUTCAPS))!=0) { MessageBox("Unable to allocate or lock memory"); return; } //检查音频输出设备是否能播放指定的音频文件 if(waveOutOpen(&hWaveOut,0,&WAVE,NULL,NULL,WAVE_ALLOWSYNC)!=0)// { MessageBox("Failed to OPEN the wave out devices"); return; } //准备待播放的数据 pWaveOutHdr.lpData =(HPSTR)lpData; pWaveOutHdr.dwBufferLength =m_WaveLong; pWaveOutHdr.dwFlags =0; if(waveOutPrepareHeader(hWaveOut,&pWaveOutHdr,sizeof(WAVEHDR))!=0) { MessageBox("Failed to prepare the wave data buffer"); return; } //播放音频数据文件 if(waveOutWrite(hWaveOut,&pWaveOutHdr,sizeof(WAVEHDR))!=0) { MessageBox("Failed to write the wave data buffer"); return;
{
// TODO: Add your control notification handler code here
waveOutClose(hWaveOut);
waveOutReset(hWaveOut); DWORD m_WaveLong;
WAVEHDR pWaveOutHdr;
WAVEOUTCAPS pwoc;
HWAVEOUT hWaveOut;
WAVEFORMATEX WAVE;
CFile fp;//
fp.Open("d:\\1.wav",CFile::modeRead);
fp.Seek(20,0);
fp.Read(&WAVE,20);
m_WaveLong=fp.GetLength();
if(lpData != NULL)
delete []lpData;
lpData=new char[m_WaveLong+1];
memset(lpData,0,sizeof(lpData));
fp.Read(lpData,m_WaveLong);
fp.Close();
if(m_WaveLong<0)
{
MessageBox("Failed to read the data chunk");
return;
}
//检查音频设备,返回音频输出设备的性能
if(waveOutGetDevCaps(WAVE_MAPPER,&pwoc,sizeof(WAVEOUTCAPS))!=0)
{
MessageBox("Unable to allocate or lock memory");
return;
}
//检查音频输出设备是否能播放指定的音频文件
if(waveOutOpen(&hWaveOut,0,&WAVE,NULL,NULL,WAVE_ALLOWSYNC)!=0)//
{
MessageBox("Failed to OPEN the wave out devices");
return;
}
//准备待播放的数据
pWaveOutHdr.lpData =(HPSTR)lpData;
pWaveOutHdr.dwBufferLength =m_WaveLong;
pWaveOutHdr.dwFlags =0;
if(waveOutPrepareHeader(hWaveOut,&pWaveOutHdr,sizeof(WAVEHDR))!=0)
{
MessageBox("Failed to prepare the wave data buffer");
return;
}
//播放音频数据文件
if(waveOutWrite(hWaveOut,&pWaveOutHdr,sizeof(WAVEHDR))!=0)
{
MessageBox("Failed to write the wave data buffer");
return;
}
Sleep(7000);
waveOutClose(hWaveOut);
waveOutReset(hWaveOut); delete []lpData;
lpData = NULL;
}怎样把上面的改成异步播放,即去掉Sleep(7000);