2012-03-22 125 views
0

我在Windows 7机器上静音麦克风时出现问题。但是我发现的所有代码都没有运行,它没有做任何事情。是否使用C#代码为Windows 7机器完成。我只需要一个开/关解决方案。 DDL文件也适用于Win x64bit。但我的事情,我创造了一个错误的另一个地方。在Windows 7上静音麦克风

 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 (MessageBox.Show("Incoming Call from: " + string.Format(e.RemoteParticipant), "Video Chat Call", MessageBoxButton.YesNo) == MessageBoxResult.Yes)发生错误,并说{ “算术运算导致溢出。”}

+0

什么是'e.RemoteParticipant'?如果你把这个string.Format放在它自己的行上,并将它保存到一个变量中,那么错误会发生在那行上呢?事实上,我没有看到只有一个参数的'string.Format'的重载,是一个扩展方法吗? – 2012-03-22 14:21:06

+0

可能的重复http://stackoverflow.com/a/3046715/285594 – YumYumYum 2017-01-31 09:16:48

回答

0

这可能帮助:Windows Mixer Control in C#

祝你好运:)。

编辑:它也可以静音某些设备,如果我是对的。

+0

似乎为我造成这个错误算术运算导致溢出。 :( – mortenstarck 2012-03-22 12:49:16

1

您可以使用音频切换器阿比 https://www.nuget.org/packages/AudioSwitcher.AudioApi.CoreAudio/4.0.0-alpha5

代码非常简单:

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); 
    } 
} 
+0

不错,看起来像'SetMuteAsync'应该是'MuteAsync',或者你可以使用'ToggleMute' – 2018-01-15 20:43:50