我需要获得正在Windows 7系统上播放的实际级别的音频,就像skype在设置中所做的那样:
skype settings http://img96.imageshack.us/img96/1497/sdgsgsdgsgd.png
我发现没关系,这里的任何人都可以帮助我吗?
我想要做的是,我想写一个简单的工具,如果窗户上的声音过于颤动,将会调高音量,如果声音太大,则会调高音量。
答案 0 :(得分:0)
您可以尝试以下链接:
http://www.dreamincode.net/forums/topic/45693-controlling-sound-volume-in-c%23/
基本上,你需要导入这个win32 api函数:
[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
那么你就可以这样使用它:
waveOutGetVolume(IntPtr.Zero, out CurrVol);
你将获得'CurrVol'的音量水平
答案 1 :(得分:0)
下载类NAudio并在C#项目中引用DLL。
然后将以下代码添加到项目中。 它将枚举所有音频设备获得其音量级别并尝试将其静音。
try
{
//Instantiate an Enumerator to find audio devices
NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();
//Get all the devices, no matter what condition or status
NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);
//Loop through all devices
foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
{
try
{
//Get its audio volume
System.Diagnostics.Debug.Print("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevel.ToString());
//Mute it
dev.AudioEndpointVolume.Mute = true;
System.Diagnostics.Debug.Print(dev.FriendlyName + " is muted");
//Get its audio volume
System.Diagnostics.Debug.Print(dev.AudioEndpointVolume.MasterVolumeLevel.ToString());
}
catch (Exception ex)
{
//Do something with exception when an audio endpoint could not be muted
System.Diagnostics.Debug.Print(dev.FriendlyName + " could not be muted");
}
}
}
catch (Exception ex)
{
//When something happend that prevent us to iterate through the devices
System.Diagnostics.Debug.Print("Could not enumerate devices due to an excepion: " + ex.Message);
}