private void UpdateDropdowns() { var Outputdevices = Controller.GetPlaybackDevices(DeviceState.Active); var Inputdevices = Controller.GetCaptureDevices(DeviceState.Active); InputDropdown.Items.Clear(); OutputDropdown.Items.Clear(); foreach (var endpoint in Inputdevices) { InputDropdown.Items.Add(endpoint.FullName); //Console.WriteLine(endpoint.Fullname); } //Console.WriteLine("These are output devices"); foreach (var endpoint in Outputdevices) { OutputDropdown.Items.Add(endpoint.FullName); //Console.WriteLine(endpoint.FullName); } var defaultInputDevice = Controller.GetDefaultDevice(DeviceType.Capture, Role.Multimedia); var defaultOutputDevice = Controller.GetDefaultDevice(DeviceType.Playback, Role.Multimedia); OutputDropdown.SelectedItem = defaultOutputDevice; OutputDropdown.Text = defaultOutputDevice.FullName; InputDropdown.SelectedItem = defaultInputDevice; InputDropdown.Text = defaultInputDevice.FullName; }
public static List <string> GetAudioDevices(string sType) { List <string> arrReturn = new List <string> { }; CoreAudioController Controller = new CoreAudioController(); if (sType == "output") { var devices = Controller.GetPlaybackDevices(DeviceState.Active); foreach (var d in devices.OrderBy(x => x.Name)) { arrReturn.Add(d.FullName); } } else if (sType == "input") { var devices = Controller.GetCaptureDevices(DeviceState.Active); foreach (var d in devices.OrderBy(x => x.Name)) { arrReturn.Add(d.FullName); } } return(arrReturn); }
private void toolStripMenuItem2_Click(object sender, EventArgs e) { micSelectorForm = new MicSelectorForm(); ComboBox comboBox = micSelectorForm.cbMics; comboBox.Items.Clear(); bool registryExists = false; ComboboxItem defaultItem = new ComboboxItem(); defaultItem.Text = DEFAULT_RECORDING_DEVICE; defaultItem.deviceId = ""; comboBox.Items.Add(defaultItem); if (selectedDeviceId == "") { registryExists = true; comboBox.SelectedIndex = comboBox.Items.Count - 1; } foreach (CoreAudioDevice device in AudioController.GetCaptureDevices()) { if (device.State == DeviceState.Active) { ComboboxItem item = new ComboboxItem(); item.Text = device.FullName; item.deviceId = device.Id.ToString(); comboBox.Items.Add(item); if (item.deviceId == selectedDeviceId) { registryExists = true; comboBox.SelectedIndex = comboBox.Items.Count - 1; } } } if (!registryExists) { ComboboxItem item = new ComboboxItem(); item.Text = "(unavailable) " + registryDeviceName.ToString(); item.deviceId = selectedDeviceId.ToString(); comboBox.Items.Add(item); comboBox.SelectedIndex = comboBox.Items.Count - 1; } DialogResult result = micSelectorForm.ShowDialog(); Console.WriteLine(result); ComboboxItem selectedItem = (ComboboxItem)comboBox.SelectedItem; registryKey.SetValue(registryDeviceId, selectedItem.deviceId); registryKey.SetValue(registryDeviceName, selectedItem.Text); selectedDeviceName = selectedItem.Text; selectedDeviceId = selectedItem.deviceId; micSelectorForm.Dispose(); UpdateSelectedDevice(); }
public static void FindSoundDeviceByName(string sType, string sName) { CoreAudioController Controller = new CoreAudioController(); CoreAudioDevice device = null; if (sType == "input") { var devices = Controller.GetCaptureDevices(DeviceState.Active); foreach (var d in devices) { if (d.FullName == sName) { device = d; } } } else { var devices = Controller.GetDevices(DeviceState.Active); foreach (var d in devices) { if (d.FullName == sName) { device = d; } } } if (device != null) { ChangeStandardSoundDevice(device); } }
static void Main(string[] args) { Console.WriteLine("Microphone un-muter by P Dring"); Console.WriteLine("This program will detect and unmute all microphones / webcams"); Console.WriteLine("Detecting microphones..."); CoreAudioController controller = new CoreAudioController(); foreach (CoreAudioDevice device in controller.GetCaptureDevices()) { Console.Write(" > Detected: " + device.FullName + ": "); if (device.IsMuted) { Console.Write("Muted - attempting to unmute"); device.Mute(false); if (device.IsMuted) { Console.Write(" failed :("); } else { Console.Write(" success :)"); } } else { Console.Write("Unmuted"); } Console.WriteLine(); } Console.WriteLine("Done - press enter to close this window"); Console.ReadLine(); }
public static void GetMicAsync() { if (device == null) { var devices = audioController.GetCaptureDevices(DeviceState.Active); device = devices.FirstOrDefault(x => x.IsDefaultDevice); } }
public MuteForm() { InitializeComponent(); this.keyHook = new GlobalKeyHook(k => GlobalKeyPress(k)); this.audioController = new CoreAudioController(); this.captureDevices = audioController.GetCaptureDevices().ToArray(); Guid lastUsedUnmuteDeviceId = Properties.Settings.Default.DeviceId; CoreAudioDevice initialMuteDevice = captureDevices.FirstOrDefault(d => !lastUsedUnmuteDeviceId.Equals(Guid.Empty) && lastUsedUnmuteDeviceId.Equals(d.Id)) ?? captureDevices.FirstOrDefault(d => d.IsDefaultCommunicationsDevice) ?? captureDevices.FirstOrDefault(d => !d.IsMuted) ?? captureDevices.FirstOrDefault(); if (initialMuteDevice == null) { MessageBox.Show("No capture device found"); Application.Exit(); return; } int unmuteTime = Properties.Settings.Default.UnmuteTimeMs; Debug.WriteLine($"Loaded settings, using unmute time {unmuteTime} ms, deviceid={lastUsedUnmuteDeviceId}"); Text = ProgramInfo.NameAndVersion; deviceCombo.Items.AddRange(captureDevices.Select(x => new ComboBoxItem(x, x.FullName)).ToArray()); pausedCheckbox.CheckedChanged += (s, e) => muter.Pause(pausedCheckbox.Checked); deviceCombo.SelectedIndexChanged += (s, e) => muter.SetDevice(((ComboBoxItem)deviceCombo.SelectedItem).Value as CoreAudioDevice); unmuteTimeTrackbar.ValueChanged += (s, e) => { int t = UnmuteTimeSliderIncrement * unmuteTimeTrackbar.Value; muter.UnmuteTimeMs = t; unmuteTimeLabel.Text = $"{t} ms"; }; this.muter = new Muter(); this.muter.MutedChanged += (s, e) => InvokeIfRequired(() => Text = muter.DeviceMuted ? $"{ProgramInfo.NameAndVersion}*" : $"{ProgramInfo.NameAndVersion}"); if (unmuteTime > unmuteTimeTrackbar.Maximum * UnmuteTimeSliderIncrement || unmuteTime < unmuteTimeTrackbar.Minimum * UnmuteTimeSliderIncrement) { unmuteTime = GetDefaultsettingsInt(nameof(Properties.Settings.UnmuteTimeMs)); } unmuteTimeTrackbar.Value = unmuteTime / UnmuteTimeSliderIncrement; deviceCombo.SelectedItem = new ComboBoxItem(initialMuteDevice, initialMuteDevice.FullName); }
int API_List(string Type) { IEnumerable <CoreAudioDevice> Target; if (Type.Equals("API-ListInputs")) { Target = controller.GetPlaybackDevices(); } if (Type.Equals("API-ListOutputs")) { Target = controller.GetCaptureDevices(); } else { Target = controller.GetDevices(); } foreach (CoreAudioDevice device in Target) { output += "Name : " + device.Name + " Type : " + device.DeviceType.ToString() + Environment.NewLine; } return(0); }
static int API_List(string Type) { AllocConsole(); IEnumerable <CoreAudioDevice> Target; if (Type.Equals("API-ListInputs")) { Target = controller.GetPlaybackDevices(); } if (Type.Equals("API-ListOutputs")) { Target = controller.GetCaptureDevices(); } else { Target = controller.GetDevices(); } foreach (CoreAudioDevice device in Target) { System.Console.WriteLine("Name : " + device.Name + " Type : " + device.DeviceType.ToString()); } return(0); }
public IEnumerable <CoreAudioDevice> GetAudioDevices() { return(controller.GetCaptureDevices(DeviceState.Active)); }