编程语言
首页 > 编程语言> > C# 获取麦克风音量并设置音量,获取扬声器音量

C# 获取麦克风音量并设置音量,获取扬声器音量

作者:互联网

  //获取系统麦克风音量
    //private int GetCurrentSpeakerVolume()
    //{
    //    int volume = 0;
    //    var enumerator = new MMDeviceEnumerator();

    //    //获取音频输出设备
    //    IEnumerable<MMDevice> speakDevices = enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).ToArray();
    //    if (speakDevices.Count() > 0)
    //    {
    //        MMDevice mMDevice = speakDevices.ToList()[0];
    //        volume = Convert.ToInt16(mMDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100);
    //    }
    //    return volume;
    //}
    //设置当前系统麦克风音量 volume 取值 0-100

    //private void GetCurrentSpeakerVolume(int volume)
    //{
    //var enumerator = new MMDeviceEnumerator();
    //IEnumerable<MMDevice> speakDevices = enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).ToArray();
    //if (speakDevices.Count() > 0)
    //{

    //    MMDevice mMDevice = speakDevices.ToList()[0];
    //    mMDevice.AudioEndpointVolume.MasterVolumeLevelScalar = volume / 100.0f;
    //}
    //}

    //获取当前系统扬声器音量
    //private int GetCurrentSpeakerVolume()
    //{
    //    int volume = 0;
    //    var enumerator = new MMDeviceEnumerator();

    //    //获取音频输出设备
    //    IEnumerable<MMDevice> speakDevices = enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).ToArray();
    //    if (speakDevices.Count() > 0)
    //    {
    //        MMDevice mMDevice = speakDevices.ToList()[0];
    //        volume = Convert.ToInt16(mMDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100);
    //    }
    //    return volume;
    //}

 

标签:enumerator,C#,volume,获取,int,音量,mMDevice,speakDevices
来源: https://www.cnblogs.com/qq2351194611/p/13905483.html