|
现在我做的项目中会使用到声音设置的功能。上网查了一些资料,以下是接口实现:
int CSMMCSetting_SetVolumeValue(int nValue)
{
int nVolume;
UINT id;
HWAVEOUT hwo;
WAVEFORMATEX waveformat;
waveformat.wFormatTag = WAVE_FORMAT_PCM;
waveformat.nChannels = 1;
waveformat.nSamplesPerSec = 8000 * 1000;
waveformat.wBitsPerSample = 8;
waveformat.nBlockAlign = waveformat.nChannels * waveformat.wBitsPerSample / 8;
waveformat.nAvgBytesPerSec = waveformat.nSamplesPerSec * waveformat.nBlockAlign;
waveformat.cbSize = 0;
SYS_Print("[CSMMCSetting_SetVolumeValue]%d\n", waveOutGetNumDevs());
for ( id = 0; id < waveOutGetNumDevs(); id++)
{
if (waveOutOpen(&hwo, id, &waveformat, 0, 0, CALLBACK_NULL) == MMSYSERR_NOERROR)
{
nVolume = ( (DWORD)(0xFFFF /100.0 * nValue) );
if (MMSYSERR_NOERROR == waveOutSetVolume(hwo, nVolume))
{
}
if(MMSYSERR_NOERROR == waveOutClose(hwo))
{
}
}
else
{
return FAILURE;
}
}
return SUCCESS;
}
试了一下好像不行啊。请高手指点一下,这其中有什么错误?nValue范围是0-100。请帮忙,定谢!
|
|