2012-03-22 222 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