繁体   English   中英

如何访问当前系统音频声音以查看实际音量?

[英]How to access current system audio sound to see actual sound volume?

我需要获得在 Windows 7 系统上播放的实际音频级别,就像 Skype 在设置中所做的一样:

Skype 设置

我什么都没找到,这里有人可以帮助我吗?

我想要做的是,我想编写一个简单的工具,如果 Windows 上的声音太安静,它将调高最大音量,或者如果声音太大,则将其调低。

你可以试试这个链接:

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”的音量级别

下载类 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);
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM