internal static MMDevice GetCaptureDevice() { if (dev == null) { MMDeviceEnumerator Devices = new MMDeviceEnumerator(); if (string.IsNullOrEmpty(Config.Current.sValue[Enums.sValue.MicDeviceName])) { dev = Devices.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications); Config.Current.sValue[Enums.sValue.MicDeviceName] = dev.ToString(); } else { MMDeviceCollection devColl = Devices.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active); for (int i = 0; devColl.Count > i; i++) { if (devColl[i].ToString() == Config.Current.sValue[Enums.sValue.MicDeviceName]) { dev = devColl[i]; break; } } if (dev == null) { Devices.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications); } } } return(dev); }
private void setDefaultDevice() { MMDevice defaultDevice = nAudioHandler.getDefaultDevice(); if (defaultDevice != null) { string defaultDeviceName = defaultDevice.ToString(); foreach (string s in inputDevices.Items) { for (int i = 0; i < s.Length; i++) { if (i == s.Length - 1 && s[i] == defaultDeviceName[i]) { inputDevices.SelectedIndex = inputDevices.Items.IndexOf(defaultDeviceName.Substring(0, s.Length)); } if (s[i] != defaultDeviceName[i]) { continue; } } } } else { inputDevices.SelectedItem = null; } }
public void DefaultDevice() { var enumerator = new MMDeviceEnumerator(); MMDevice defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console); NAudioHandler handler = new NAudioHandler(); MMDevice device = handler.getDefaultDevice(); Assert.AreEqual(device.ToString(), defaultDevice.ToString()); }
private void setDefaultDevice() { NAudioHandler nAudioHandler = new NAudioHandler(); MMDevice defaultDevice = nAudioHandler.getDefaultDevice(); if (defaultDevice != null) { inputDevices.SelectedIndex = inputDevices.Items.IndexOf(defaultDevice.ToString()); } }
public string getDefaultDirectDevice() { var enumerator = new MMDeviceEnumerator(); MMDevice defaultDevice = null; try { defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console); } catch (Exception ex) { Console.WriteLine(ex); } return(defaultDevice.ToString().Substring(0, 31)); }
private void btnSelectDevice_Click(object sender, EventArgs e) { if (listDevices.SelectedItems.Count > 0) { MMDevice device = (MMDevice)listDevices.SelectedItems[0].Tag; capture = new WasapiCapture(); capture.Device = device; capture.Initialize(); capture.DataAvailable -= writeEvent; capture.DataAvailable += writeEvent; btnSelectDevice.Text = "Selected!"; groupDeviceSelection.Enabled = true; Console.WriteLine("Selected device: {0}", device.ToString()); } }
private void btnSelectDevice_Click(object sender, EventArgs e) { if (listDevices.SelectedItems.Count > 0) { MMDevice device = (MMDevice)listDevices.SelectedItems[0].Tag; capture = new WasapiCapture(); /*capture = new WasapiCapture(true, AudioClientShareMode.Shared, 0, * new WaveFormat(44100, 16, 2, AudioEncoding.Extensible) * );*/ capture.Device = device; capture.Initialize(); Console.WriteLine(capture.WaveFormat); capture.DataAvailable -= writeEvent; capture.DataAvailable += writeEvent; btnSelectDevice.Text = "Selected!"; groupDeviceSelection.Enabled = true; Console.WriteLine("Selected device: {0}", device.ToString()); } }
public int GetDefaultDeviceIndex(MMDevice defaultDevice) { return(Array.IndexOf(View_AudioItems.Select(x => x.Name).ToArray(), defaultDevice.ToString())); }