Mute microphone on Windows 7

为君一笑 提交于 2019-12-25 00:06:30

问题


I have an problem with muting the mic on an windows 7 machine. But all the code i have found dosen't run ore it's not doing anything the runned. Have is it done for an Windows 7 machine using C# code. I just need an on/off solution. The DDL file works also with Win x64bit. But i thing that i creates an error another place.

        mixers.Recording.Lines.GetMixerFirstLineByComponentType(
                     MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE).Volume = 0;
            if (!mediaElement1.CheckAccess()) mediaElement1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate { mediaElement1.Play(); });


            if (MessageBox.Show("Incoming Call from: " + string.Format(e.RemoteParticipant), "Video Chat Call", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                mixers.Recording.Lines.GetMixerFirstLineByComponentType(
                             MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE).Volume = 1;
                if (!mediaElement1.CheckAccess()) mediaElement1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate { mediaElement1.Stop(); });
                _currentConversation.StartVideo();

            }'

If error occurs at if (MessageBox.Show("Incoming Call from: " + string.Format(e.RemoteParticipant), "Video Chat Call", MessageBoxButton.YesNo) == MessageBoxResult.Yes) and says {"Arithmetic operation resulted in an overflow."}


回答1:


http://www.computercabal.com/2010/11/mute-microphone-from-c-on-windows.html -- this gentleman appears to have had a similar problem, and he's provided the source code for a solution.




回答2:


You can use Audio Switcher Api https://www.nuget.org/packages/AudioSwitcher.AudioApi.CoreAudio/4.0.0-alpha5

Code is quite simple:

private async void btnMute_ButtonClick(object sender, EventArgs e)
{
    var audioController = new CoreAudioController();
    var devices = await audioController.GetDevicesAsync(DeviceType.Capture, DeviceState.Active);
    var device = devices.FirstOrDefault(x => x.IsDefaultDevice);
    if(device != null) {
        await device.SetMuteAsync(!device.IsMuted);
    }
}



回答3:


this might help: Windows Mixer Control in C#

Good luck :).

EDIT: It can also mute certain devices if I'm right.



来源:https://stackoverflow.com/questions/9821969/mute-microphone-on-windows-7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!