我用C ++创建了一个播放音乐的服务器和客户端。我现在正在尝试创建通知,指定声音缓冲区播放何时达到其大小的四分之一或四分之三。
//Create event handles
LPDIRECTSOUNDNOTIFY8 directSoundNotify;
HANDLE playEventHandles[2];
playEventHandles[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
playEventHandles[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
buffer->QueryInterface(IID_IDirectSoundNotify8, (LPVOID*)&directSoundNotify);
//Assign handles to DSBPOSITIONNOTIFY array
DSBPOSITIONNOTIFY positionNotify[3];
positionNotify[0].dwOffset = bufferSize / 4; //One quarter of the size
positionNotify[0].hEventNotify = playEventHandles[0];
positionNotify[1].dwOffset = bufferSize - (bufferSize / 4); //Three quarters of the size
positionNotify[1].hEventNotify = playEventHandles[1];
directSoundNotify->SetNotificationPositions(1, positionNotify);
directSoundNotify->Release();
buffer->SetCurrentPosition(0);
buffer->Play(0, 0, 0);
//Wait for notifications
WaitForMultipleObjects(2, playEventHandles, FALSE, INFINITE);
if (/*First notification occurs*/)
{
//Do something
}
else if (/*Second notification occurs*/)
{
//Do something else
}
我应该在代码底部的if语句中添加什么才能确定通知何时发生?或者我应该使用if语句以外的其他方式处理通知?如果是这样,我该如何处理通知并确定它们是否已经发生?