Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# windows7c中的音量控制#_C#_Windows 7_Sdk_Volume - Fatal编程技术网

C# windows7c中的音量控制#

C# windows7c中的音量控制#,c#,windows-7,sdk,volume,C#,Windows 7,Sdk,Volume,我知道这个话题以前已经在这里讨论过了,但我还是没法让它发挥作用。 我只需要在我的机器中获得当前的卷(我将从那里开始,我想在之后扩展我的项目的功能会更容易),使用win 7 SDK,而不使用来自已发布项目的代码,如。我应该为我的项目添加一个特定的引用吗?使用dllimport? 如果您有任何帮助,我们将不胜感激。可能需要以下帮助:(ISimpleAudioVolume接口) --编辑-- 此项目似乎包含您正在搜索的内容 如果没有,你可以到这里看看: 或在此: 但是我找到的最好的代码总是返回到你在

我知道这个话题以前已经在这里讨论过了,但我还是没法让它发挥作用。 我只需要在我的机器中获得当前的卷(我将从那里开始,我想在之后扩展我的项目的功能会更容易),使用win 7 SDK,而不使用来自已发布项目的代码,如。我应该为我的项目添加一个特定的引用吗?使用dllimport? 如果您有任何帮助,我们将不胜感激。

可能需要以下帮助:(ISimpleAudioVolume接口)

--编辑--

此项目似乎包含您正在搜索的内容

如果没有,你可以到这里看看:

或在此:

但是我找到的最好的代码总是返回到你在问题中给出的链接。祝你好运

--编辑2--

或者,您可以使用FMOD(c++),并借助以下工具:
而这个:

可能是这样的:(ISimpleAudioVolume接口)

--编辑--

此项目似乎包含您正在搜索的内容

如果没有,你可以到这里看看:

或在此:

但是我找到的最好的代码总是返回到你在问题中给出的链接。祝你好运

--编辑2--

或者,您可以使用FMOD(c++),并借助以下工具:

这是:

使用核心音频API,下面的类将允许您获取并设置用于播放的默认音频端点的音量

using CoreAudioApi;

public class SystemVolumeConfigurator
{
        private readonly MMDeviceEnumerator _deviceEnumerator = new MMDeviceEnumerator();
        private readonly MMDevice _playbackDevice;

        public SystemVolumeConfigurator()
        {
            _playbackDevice = _deviceEnumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
        }

        public int GetVolume()
        {
            return (int)(_playbackDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100);
        }

        public void SetVolume(int volumeLevel)
        {
            if (volumeLevel < 0 || volumeLevel > 100)
                throw new ArgumentException("Volume must be between 0 and 100!");

            _playbackDevice.AudioEndpointVolume.MasterVolumeLevelScalar = volumeLevel / 100.0f;
        }
}
使用CoreAudioApi;
公共类SystemVolumeConfigulator
{
私有只读MMDeviceEnumerator _deviceEnumerator=新MMDeviceEnumerator();
专用只读MMDevice\u播放设备;
公共系统卷配置器()
{
_playbackDevice=\u deviceEnumerator.GetDefaultAudioEndpoint(EDataFlow.eRender、ERole.eMultimedia);
}
public int GetVolume()
{
返回(int)(_playbackDevice.AudioEndpointVolume.MasterVolumeLevelScalar*100);
}
公共void设置卷(int volumeLevel)
{
如果(容积水平<0 | |容积水平>100)
抛出新ArgumentException(“卷必须介于0和100之间!”);
_playbackDevice.AudioEndpointVolume.MasterVolumeLevel Scalar=volumeLevel/100.0f;
}
}

使用核心音频API,以下类将允许您获取并设置默认音频端点的音量以进行播放

using CoreAudioApi;

public class SystemVolumeConfigurator
{
        private readonly MMDeviceEnumerator _deviceEnumerator = new MMDeviceEnumerator();
        private readonly MMDevice _playbackDevice;

        public SystemVolumeConfigurator()
        {
            _playbackDevice = _deviceEnumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
        }

        public int GetVolume()
        {
            return (int)(_playbackDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100);
        }

        public void SetVolume(int volumeLevel)
        {
            if (volumeLevel < 0 || volumeLevel > 100)
                throw new ArgumentException("Volume must be between 0 and 100!");

            _playbackDevice.AudioEndpointVolume.MasterVolumeLevelScalar = volumeLevel / 100.0f;
        }
}
使用CoreAudioApi;
公共类SystemVolumeConfigulator
{
私有只读MMDeviceEnumerator _deviceEnumerator=新MMDeviceEnumerator();
专用只读MMDevice\u播放设备;
公共系统卷配置器()
{
_playbackDevice=\u deviceEnumerator.GetDefaultAudioEndpoint(EDataFlow.eRender、ERole.eMultimedia);
}
public int GetVolume()
{
返回(int)(_playbackDevice.AudioEndpointVolume.MasterVolumeLevelScalar*100);
}
公共void设置卷(int volumeLevel)
{
如果(容积水平<0 | |容积水平>100)
抛出新ArgumentException(“卷必须介于0和100之间!”);
_playbackDevice.AudioEndpointVolume.MasterVolumeLevel Scalar=volumeLevel/100.0f;
}
}

谢谢,但是如何从我的c#代码中引用此接口?我读过这篇文章,没有发现关于如何使用itOr的任何线索。你可以试着问这个问题:你能解释一下如何在我的c代码中使用它吗HeFest'给了我一个例外,我知道非托管代码可以在.NET中使用,但是这是个例子吗?抱歉,经过更多的研究,我发现这是C++代码…我编辑了我的帖子。谢谢,但是我如何从我的c#代码中引用这个界面呢?我读过这篇文章,没有发现关于如何使用itOr的任何线索。你可以试着问这个问题:你能解释一下如何在我的c代码中使用它吗HeFest'给了我一个例外,我知道非托管代码可以在.NET中使用,但是这是个例子吗?抱歉,经过更多的研究,我发现这是C++代码…我编辑了我的帖子。