如何检测是否任何声音Windows XP机器上播放 [英] How to detect if any sound plays on a windows xp machine

查看:161
本文介绍了如何检测是否任何声音Windows XP机器上播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检测是否任何声音的Windows XP计算机上播放?帮助在任何语言将是有益的。基本上,我需要编写运行所有的时间和输出一些文字每当播放声音文件的程序。我不需要对任何声音的具体信息,健全的只是是否正在播放。我不在乎扬声器是否真的开机或类似的东西。

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.

推荐答案

这个问题很简单,但答案是困难的。你需要使用的DirectSound达到你的目的。我没有测试过我的解决办法,但你可以尝试调用<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.idirectsoundbuffer8.idirectsoundbuffer8.getstatus%28VS.85%29.aspx\"相对=nofollow> IDirectSoundBuffer8的getStatus ::(),然后检查的 pdwStatus 的参数的返回值。根据MSDN, DSBSTATUS_PLAYING 如果正在审理的缓冲区设置。

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;

更新

我刚刚发现了大约如何检测沉默讨论了VB论坛(无声卡的输出)。下载 DetSilence.zip 。在 DXRecord_GotWavData 子,修改常量 SilencePercent NonSilencePercent 该值你的需要。

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.

这篇关于如何检测是否任何声音Windows XP机器上播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆