public static bool ToggleMuteWindowsAudioDevices(bool muted = false) { //Instantiate an Enumerator to find audio devices NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); //Get all the devices, no matter what condition or status NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All); //Loop through all devices foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { try { //Show us the human understandable name of the device //System.Diagnostics.Debug.Print(dev.FriendlyName); if (dev.State == DeviceState.Active) { //[Un]Mute it dev.AudioEndpointVolume.Mute = muted; } } catch (Exception ex) { //Do something with exception when an audio endpoint could not be muted return(false); } } return(true); }
private void Form1_Load(object sender, EventArgs e) { //Check windows if (Environment.OSVersion.Version.Major < 6) { MessageBox.Show("You are using an unsupported version of Windows.\n\n" + "audio-output-recorder requires Windows Vista or newer (which supports WASAPI).", "Unsupported version of Windows", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Check for ffmpeg.exe if (System.IO.File.Exists(Environment.CurrentDirectory + "\\ffmpeg.exe") == false) { if (MessageBox.Show("No ffmpeg.exe could not be found in the current directory." + "\n\nWould you like to open up a web browser window with a website where you can download ffmpeg? " + "Choose 32-bit static if you're unsure and put ffmpeg.exe in the same folder as audio-output-recorder.", "Error", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { System.Diagnostics.Process.Start("http://ffmpeg.zeranoe.com/builds/"); Environment.Exit(0); } else { chkDownsample.Checked = false; chkDownsample.Enabled = false; chkEncode.Checked = false; chkEncode.Enabled = false; } } if (System.IO.Directory.Exists(Properties.Settings.Default.recordingPath)) { txtOutput.Text = Properties.Settings.Default.recordingPath; } else { txtOutput.Text = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); } NAudio.CoreAudioApi.MMDeviceEnumerator devEnum = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection devColl = devEnum.EnumerateAudioEndPoints( NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active); foreach (NAudio.CoreAudioApi.MMDevice d in devColl) { cDevice.Items.Add(d.FriendlyName); } if (cDevice.Items.Count > 0) { cDevice.Text = cDevice.Items[0].ToString(); } cBitrate.Text = "192k"; }