private void detectDevices() { MMDeviceEnumerator deviceEnum = new MMDeviceEnumerator(); //get audio capturing devices inputDevices = deviceEnum.EnumAudioEndpoints(DataFlow.Capture, DeviceState.Active); MMDevice activeDevice = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia); foreach (MMDevice device in inputDevices) { comboBox_mic.Items.Add(device.FriendlyName); if (device.DeviceID == activeDevice.DeviceID) { comboBox_mic.SelectedIndex = comboBox_mic.Items.Count - 1; } } //Find speakers or headphones activeDevice = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); outputDevices = deviceEnum.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active); foreach (MMDevice device in outputDevices) { comboBox_speaker.Items.Add(device.FriendlyName); if (device.DeviceID == activeDevice.DeviceID) { comboBox_speaker.SelectedIndex = comboBox_speaker.Items.Count - 1; } } }
private void MainForm_Load(object sender, EventArgs e) { //Find sound capture devices and fill the cmbInput combo MMDeviceEnumerator deviceEnum = new MMDeviceEnumerator(); mInputDevices = deviceEnum.EnumAudioEndpoints(DataFlow.Capture, DeviceState.Active); MMDevice activeDevice = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia); foreach (MMDevice device in mInputDevices) { cmbInput.Items.Add(device.FriendlyName); if (device.DeviceID == activeDevice.DeviceID) { cmbInput.SelectedIndex = cmbInput.Items.Count - 1; } } //Find sound render devices and fill the cmbOutput combo activeDevice = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); mOutputDevices = deviceEnum.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active); foreach (MMDevice device in mOutputDevices) { cmbOutput.Items.Add(device.FriendlyName); if (device.DeviceID == activeDevice.DeviceID) { cmbOutput.SelectedIndex = cmbOutput.Items.Count - 1; } } }
public void CreateDevice(EventHandler <DefaultDeviceChangedEventArgs> aDefaultDeviceChangedHandler, EventHandler <AudioEndpointVolumeCallbackEventArgs> aVolumeChangedHandler) { try { //Create device and register default device change notification _mMdeviceEnumerator = new MMDeviceEnumerator(); iMultiMediaNotificationClient = new MMNotificationClient(_mMdeviceEnumerator); iMultiMediaNotificationClient.DefaultDeviceChanged += iDefaultDeviceChangedHandler = aDefaultDeviceChangedHandler; var mMdeviceList = _mMdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active); if (mMdeviceList != null && mMdeviceList.Count > 0) { _mMdevice = _mMdeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); GUIGraphicsContext.CurrentAudioRendererDevice = _mMdevice.FriendlyName; //Register to get volume modifications if (_mMdevice != null) { iAudioEndpointVolume = AudioEndpointVolume.FromDevice(_mMdevice); } iAudioEndpointVolumeMixerCallback = new CSCore.CoreAudioAPI.AudioEndpointVolumeCallback(); iAudioEndpointVolumeMixerCallback.NotifyRecived += iVolumeChangedHandler = aVolumeChangedHandler; iAudioEndpointVolume?.RegisterControlChangeNotify(iAudioEndpointVolumeMixerCallback); } // For audio session Stop(); //DispatchingTimerStart(); // Disable because the check will be done in IsMuted code } catch (Exception) { // When no device available } }
public void refreshDevices() { fo.frm1.deviceList.Items.Clear(); using (var deviceEnumerator = new MMDeviceEnumerator()) using (var deviceCollection = deviceEnumerator.EnumAudioEndpoints( CaptureMode == "Capture" ? DataFlow.Capture : DataFlow.Render, DeviceState.Active)) { foreach (var device in deviceCollection) { var deviceFormat = WaveFormatFromBlob(device.PropertyStore[ new PropertyKey(new Guid(0xf19f064d, 0x82c, 0x4e27, 0xbc, 0x73, 0x68, 0x82, 0xa1, 0xbb, 0x8e, 0x4c), 0)].BlobValue); var it = device + " " + deviceFormat.Channels.ToString(CultureInfo.InvariantCulture); var item = new ListViewItem(device.FriendlyName) { Tag = device }; item.SubItems.Add(deviceFormat.Channels.ToString(CultureInfo.InvariantCulture)); fo.frm1.deviceList.Items.Add(item); } } }
private static List <VolumeObject> GetAllVolumeObjects() { List <VolumeObject> volumeObjects = new List <VolumeObject>(); // get the speakers (1st render + multimedia) device using (MMDeviceEnumerator deviceEnumerator = new MMDeviceEnumerator()) { // Find all the different "devices"/endpoints on PC using (var endpoints = deviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { foreach (var endpoint in endpoints) { using (AudioSessionManager2 mgr = new AudioSessionManager2(endpoint.Activate(GUID_IAudioSessionManager2, CLSCTX.CLSCTX_ALL, IntPtr.Zero))) { using (var sessionEnumerator = mgr.GetSessionEnumerator()) { foreach (var session in sessionEnumerator) { // Note: This means audioSession must be disposed of AudioSessionControl2 audioSession = session.QueryInterface <AudioSessionControl2>(); volumeObjects.Add(new VolumeObject(audioSession.ProcessID, audioSession)); } } } } } } return(volumeObjects); }
private static ISoundOut GetWasApiSoundOut(ISoundOutDevice device) { MMDevice mmDevice = null; if (device.Id == WindowsDefaultId) { mmDevice = GetDefaultDevice(); } if (mmDevice == null) { using (var enumerator = new MMDeviceEnumerator()) { using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { if (devices == null || devices.Count == 0) { throw new NoDeviceFoundException(); } mmDevice = devices.FirstOrDefault(x => x.DeviceID == device.Id) ?? GetDefaultDevice() ?? devices.First(); } } } return(new WasapiOut { Device = mmDevice, UseChannelMixingMatrices = false }); }
public MMDeviceCollection GetMicrophoneDevices() { var deviceEnumerator = new MMDeviceEnumerator(); _microphones = deviceEnumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.Active); return(_microphones); }
//Get audio devices to play audio out private void SetDevices() { using (var mmdeviceEnumerator = new MMDeviceEnumerator()) { using ( var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { foreach (var device in mmdeviceCollection) { audioDevice.Items.Add(device); if (device.DeviceState == DeviceState.Active) { audioDevice.SelectedIndex = audioDevice.Items.IndexOf(device); } } } } if (audioDevice.Items.Count <= 0) { throw new Exception("No audio devices found!"); } activeDevice = (MMDevice)audioDevice.SelectedItem; }
public MMDeviceCollection GetSpeakerDevices() { var deviceEnum = new MMDeviceEnumerator(); _speakers = deviceEnum.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active); return(_speakers); }
public MMDevice GetDefaultSpeaker() { var devicesEnum = new MMDeviceEnumerator(); var devicesCollection = devicesEnum.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active); return(devicesCollection[0]); }
public MMDevice GetDefaultMicrophone() { var devicesEnum = new MMDeviceEnumerator(); var devicesCollection = devicesEnum.EnumAudioEndpoints(DataFlow.Capture, DeviceState.Active); return(devicesCollection[0]); }
private static void switchAudioDevice() { var endPoints = (from device in _devEnum.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active) where device.DeviceState == DeviceState.Active select device).ToList(); for (int i = 0; i < endPoints.Count; i++) { if (endPoints[i].DeviceID == _device.DeviceID) { if (i < endPoints.Count - 1) { _device = endPoints[i + 1]; } else { _device = endPoints[0]; } break; } } var pPolicyConfig = new PolicyConfigClient(); pPolicyConfig.SetDefaultEndpoint(_device.DeviceID, Role.Multimedia); OverlayHandler.Show(_device.FriendlyName); }
public static void SelectConfiguredMic(string micDeviceID) { //Get microphone devices MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); var devices = enumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.Active); //Load microphone id from config if (micDeviceID == "") { microphone = devices.FirstOrDefault(); PluginConfig.Instance.MicDeviceID = microphone.DeviceID; Plugin.Log.Info($"No device configured, using default: {microphone.FriendlyName}"); } else if (microphone != null) { if (microphone.DeviceID != micDeviceID) { microphone = enumerator.GetDevice(micDeviceID); Plugin.Log.Info($"Switching device to {microphone.FriendlyName}"); } } else { microphone = enumerator.GetDevice(micDeviceID); Plugin.Log.Info($"Using device from config: {microphone.FriendlyName}"); } }
// These WasapiCapture objects _and_ their WasapiCapture.Device members must be // Dispose()d when you're done with them. static Queue <WasapiCapture> GetAudioCaptures() { // This is run on another thread; it should not use UnityEngine APIs var q = new Queue <WasapiCapture>(); using (var deviceEnumerator = new MMDeviceEnumerator()) using (var activeDevices = deviceEnumerator.EnumAudioEndpoints( DataFlow.Render, DeviceState.Active)) { foreach (MMDevice device in activeDevices) { var audioCapture = new WasapiLoopbackCapture(); audioCapture.Device = device; try { audioCapture.Initialize(); q.Enqueue(audioCapture); } catch (CSCore.CoreAudioAPI.CoreAudioAPIException) { audioCapture.Device.Dispose(); audioCapture.Dispose(); } } } return(q); }
private void VoiceChatCommandOnCaptureDevicesReceived(object sender, EventArgs eventArgs) { RemoteCaptureDevices = _voiceChatCommand.RemoteCaptureDevices; using (var mmDeviceEnumerator = new MMDeviceEnumerator()) using (var devices = mmDeviceEnumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.Active)) using (var defaultDevice = mmDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications)) { LocalCaptureDevices = devices.Select( x => new LocalCaptureDeviceInfo { Device = x, Id = x.DeviceID, Name = x.FriendlyName, IsDefault = x.DeviceID == defaultDevice.DeviceID }).ToList(); } SelectedLocalCaptureDevice = LocalCaptureDevices.FirstOrDefault(x => x.IsDefault) ?? LocalCaptureDevices.FirstOrDefault(); SelectedRemoteCaptureDevice = RemoteCaptureDevices.FirstOrDefault(x => x.IsDefault) ?? RemoteCaptureDevices.FirstOrDefault(); }
private void Reproductor_Load(object sender, EventArgs e) { using (var enumerador = new MMDeviceEnumerator()) { using (var mmColeccion = enumerador.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { foreach (var item in mmColeccion) { _devices.Add(item); } } } Log.ImprimirMensaje("Iniciando el Reproductor en modo local", TipoMensaje.Info); try { foobar2kInstance = Process.GetProcessesByName("foobar2000")[0]; Log.ImprimirMensaje("Se ha encontrado foobar2000", TipoMensaje.Correcto); } catch (IndexOutOfRangeException) { Log.ImprimirMensaje("No se ha encontrado foobar2000", TipoMensaje.Info); foobar2kInstance = null; checkBoxFoobar.Enabled = false; } }
private bool isDeviceAvailable() { List <object> deviceList = new List <object>(); using (var deviceEnumerator = new MMDeviceEnumerator()) using (var deviceCollection = deviceEnumerator.EnumAudioEndpoints( CaptureMode == CaptureMode.Capture ? DataFlow.Capture : DataFlow.Render, DeviceState.Active)) { foreach (var device in deviceCollection) { var deviceFormat = WaveFormatFromBlob(device.PropertyStore[ new PropertyKey(new Guid(0xf19f064d, 0x82c, 0x4e27, 0xbc, 0x73, 0x68, 0x82, 0xa1, 0xbb, 0x8e, 0x4c), 0)].BlobValue); var item = new ListViewItem(device.FriendlyName) { Tag = device }; item.SubItems.Add(deviceFormat.Channels.ToString(CultureInfo.InvariantCulture)); deviceList.Add(item); } } if (deviceList.Count > 0) { return(true); } else { return(false); } }
/// <summary> /// /// </summary> public static void Init() { ExecutablePath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); try { using (var mmdeviceEnumerator = new MMDeviceEnumerator()) { using (var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { foreach (var device in mmdeviceCollection) { AudioDevices.Add(device); } } DefaultDevice = mmdeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); } } catch { System.Windows.Forms.MessageBox.Show("Audio Device Failed to Initialize", "Error Initializing Audio", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); } AddFont(Path.Combine(ExecutablePath, "lib/A-OTF_Folk_Pro_H.otf")); AddFont(Path.Combine(ExecutablePath, "lib/Palatino Linotype.ttf")); }
public IEnumerable <MMDevice> EnumerateWasapiDevices() { using (MMDeviceEnumerator enumerator = new MMDeviceEnumerator()) { return(enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)); } }
public static void Play(string filePath, Func <bool> ShouldStop = null) { using (var enumerator = new MMDeviceEnumerator()) using (var device = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active).Last()) using (var source = CodecFactory.Instance.GetCodec(filePath) .ToSampleSource() .ToMono() .ToWaveSource()) using ( var soundOut = new WasapiOut() { Latency = 100, Device = device }) { soundOut.Initialize(source); soundOut.Play(); if (ShouldStop == null) { Thread.Sleep(source.GetLength()); } else { while (!ShouldStop()) { Thread.Sleep(5000); } } soundOut.Stop(); } }
public DeviceCaptureChannel(JSONClass json) { channelName = json[nameof(channelName)]; outputFormat = (OutputFormat)json[nameof(outputFormat)].AsInt; cacheLength = json[nameof(cacheLength)].AsInt; storeInMemoryUntilSave = json[nameof(storeInMemoryUntilSave)].AsBool; var id = json[nameof(channelDevice.DeviceID)]; using (var enumerator = new MMDeviceEnumerator()) { deviceList = new List <MMDevice>(enumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.Active)); foreach (var device in deviceList) { if (device.DeviceID == id) { channelDevice = device; break; } } if (channelDevice == null) { channelDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); } } cacheLength = 60; // default cache length, for now Debug.WriteLine("Populating properties window"); propertiesWindow = new DeviceCaptureProperties { Visible = false }; propertiesWindow.Populate(this); }
private void RefreshDevices() { listViewSources.Items.Clear(); using (var deviceEnumerator = new MMDeviceEnumerator()) using (var deviceCollection = deviceEnumerator.EnumAudioEndpoints( captureMode == CaptureMode.Capture ? DataFlow.Capture : DataFlow.Render, DeviceState.Active)) { foreach (var device in deviceCollection) { if (captureMode == CaptureMode.LoopbackCapture ? device.DeviceFormat.Channels > 1 : true) { var deviceFormat = WaveFormatFromBlob(device.PropertyStore[ new PropertyKey(new Guid(0xf19f064d, 0x82c, 0x4e27, 0xbc, 0x73, 0x68, 0x82, 0xa1, 0xbb, 0x8e, 0x4c), 0)].BlobValue); var item = new ListViewItem(device.FriendlyName) { Tag = device }; item.SubItems.Add(deviceFormat.Channels.ToString(CultureInfo.InvariantCulture)); listViewSources.Items.Add(item); } } } }
private void UpdateDevices() { Devices.Clear(); foreach (var device in _deviceEnumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.Active)) { Devices.Add(device); } }
public void RefreshSoundOut() { if (Settings.SoundOutMode == SoundOutMode.DirectSound) { var enumerator = new DirectSoundDeviceEnumerator(); DirectSoundDevice device; if (Settings.SoundOutDeviceID == "-0") { using (var wasapiEnumerator = new MMDeviceEnumerator()) { device = enumerator.Devices.FirstOrDefault(x => x.Description == wasapiEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia).FriendlyName) ?? enumerator.Devices.First(); } } else { device = enumerator.Devices.FirstOrDefault(x => x.Guid.ToString() == Settings.SoundOutDeviceID); if (device == null) { Settings.SoundOutDeviceID = "-0"; RefreshSoundOut(); return; } } _soundOut = new DirectSoundOut { Device = device.Guid, Latency = Settings.Latency }; } else { MMDevice device; using (var enumerator = new MMDeviceEnumerator()) { if (Settings.SoundOutDeviceID == "-0") { device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); } else { using (MMDeviceCollection devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { device = devices.FirstOrDefault(x => x.DeviceID == Settings.SoundOutDeviceID); if (device == null) { Settings.SoundOutDeviceID = "-0"; RefreshSoundOut(); return; } } } } _soundOut = new WasapiOut { Device = device, Latency = Settings.Latency }; } _soundOut.Stopped += soundOut_Stopped; }
//############################################################################################################################################################################################## /// <summary> /// Return a list with all active capture device names /// </summary> /// <returns>List with all active capture device names</returns> public static List <string> GetRecordingDeviceNames() { MMDeviceEnumerator devEnumerator = new MMDeviceEnumerator(); MMDeviceCollection mMDevices = devEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active); List <string> deviceNames = mMDevices.Select(d => d.FriendlyName).ToList(); deviceNames.Add("Default playback device"); return(deviceNames); }
private MMDevice GetAudioDevice(string deviceId) { using (var mmDeviceEnumerator = new MMDeviceEnumerator()) { return (mmDeviceEnumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.Active) .FirstOrDefault(x => x.DeviceID == deviceId)); } }
private void UpdateDevices() { Application.Current.Dispatcher.Invoke(() => { Devices.Clear(); foreach (var device in _deviceEnumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.Active)) { Devices.Add(device); } }); }
void Start() { devices = new List <MMDevice>(); var ayy = new MMDeviceEnumerator(); foreach (MMDevice device in ayy.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { devices.Add(device); } }
private MMDevice GetFirstDevice() { using (var mmdeviceEnumerator = new MMDeviceEnumerator()) { using ( var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { return(mmdeviceCollection[0]); } } }
public static void UpdateMicrophoneList() { MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); micSelectOptions.Clear(); foreach (var mic in enumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.Active)) { micSelectOptions.Add(mic.FriendlyName); micDeviceList.Add(mic.FriendlyName, mic.DeviceID); } }