Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
536 views
in Technique[技术] by (71.8m points)

perl - How to detect if any sound plays on a windows xp machine

Is it possible to detect if any sound plays on a windows xp machine? Help in any language would be useful. I basically need to write a program that runs all the time and outputs some text to a file whenever a sound plays. I don't need any specific information about the sound, just whether a sound is playing. I don't care whether the speakers are actually powered on or anything like that.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The question was easy, but the answer is difficult. You'll need to utilize DirectSound to achieve your purpose. I haven't tested my solution yet, but you can try to call IDirectSoundBuffer8::GetStatus(), then check the return value of pdwStatus parameter. According to MSDN, DSBSTATUS_PLAYING is set if the buffer is being heard.

Since you didn't tell about programming language you are using, I implement the following example using my favorite language, Delphi.

  var
    dwStatus: DWORD;
    hResult: HRESULT;

  hResult := GetStatus(@dwStatus);
  if hResult = DS_OK then begin
    if dwStatus and DSBSTATUS_PLAYING <> 0 then
      ShowMessage('Sound card is playing sound now.');
  end;

UPDATE

I just found a VB forum discussed about how to detect silence (no output of sound card). Download DetSilence.zip. In the DXRecord_GotWavData Sub, modify the constants SilencePercent and NonSilencePercent to the values you need.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...