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;
    //}

 

上一篇:dotnet C# 如何正确获取藏文的字数


下一篇:c# – 使用.GetType()可能多次枚举IEnumerable警告