protected override void Dispose(bool disposing) { if (disposing) { if (notifyIcon != null) { notifyIcon.Dispose(); } if (notifyContextMenu != null) { notifyContextMenu.Dispose(); } if (enumerator != null) { if (nc != null) { enumerator.UnregisterEndpointNotificationCallback(nc); } enumerator.Dispose(); } if (delayedNotification != null) { delayedNotification.Dispose(); } } base.Dispose(disposing); }
protected virtual void Dispose(bool disposing) { if (disposing) { // free managed resources if (soundInSource != null) { soundInSource.Dispose(); soundInSource = null; } if (mMDeviceEnumerator != null) { mMDeviceEnumerator.Dispose(); mMDeviceEnumerator = null; } if (mMNotificationClient != null) { mMNotificationClient.Dispose(); mMNotificationClient = null; } if (_soundIn != null) { _soundIn.Dispose(); _soundIn = null; } } }
public IWavePlayer CreateWavePlayer(MediaFile File) { MMDevice dev = null; MMDeviceEnumerator deven = new MMDeviceEnumerator(); if (string.IsNullOrEmpty(DeviceID)) { dev = deven.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); } else { dev = deven.GetDevice(DeviceID); } deven.Dispose(); if (Shared) { return(new WasapiOut(dev, AudioClientShareMode.Shared, EventSync, Latency)); } else { return(new WasapiOut(dev, AudioClientShareMode.Exclusive, EventSync, Latency)); } }
protected virtual void Dispose(bool disposing) { if (disposing) { _deviceEnumerator?.Dispose(); } }
public void Dispose() { try { // Do unregistration, can throw if (_deviceEnumerator != null) { _deviceEnumerator.DefaultDeviceChanged -= OnDefaultDeviceChanged; _deviceEnumerator.DeviceRemoved -= OnDeviceRemoved; _deviceEnumerator.DeviceStateChanged -= OnDeviceStateChanged; } if (_callback != null) { _callback.NotifyRecived -= OnEndpointVolumeChanged; } if (_endpointVolume != null) { _endpointVolume.UnregisterControlChangeNotify(_callback); } } catch { } // Do disposal chains, each can throw try { _deviceEnumerator.Dispose(); } catch { } try { Device.Dispose(); } catch { } // Set to null _deviceEnumerator = null; _endpointVolume = null; _callback = null; Device = null; }
public void Refresh() { deviceEnumerator = new MMDeviceEnumerator(); try { render = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); renderAudioSessionManager = render.AudioSessionManager; renderSessions = renderAudioSessionManager.Sessions; } catch { // no available speaker device } try { capture = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia); captureAudioSessionManager = capture.AudioSessionManager; captureSessions = captureAudioSessionManager.Sessions; } catch { // no available recording device } deviceEnumerator.Dispose(); }
public void Dispose() { if (_enumerator != null) { _enumerator.Dispose(); _enumerator = null; } }
public void Dispose() { _deviceEnumerator.UnregisterEndpointNotificationCallback(_notificationClient); _notificationClient = null; _deviceEnumerator.Dispose(); _deviceEnumerator = null; }
private MMDevice getPrimaryMicDevice() { var enumerator = new MMDeviceEnumerator(); var result = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications); enumerator.Dispose(); return(result); }
public void Dispose() { _deviceEnumerator.UnregisterEndpointNotificationCallback(_notificationClient); _logger.Verbose("Audio device event interface unregistered."); _deviceEnumerator?.Dispose(); _deviceEnumerator = null; _logger.Verbose("Audio device enumerator service disposed."); }
public override void Disable() { _notificationClient.DefaultDeviceChanged -= NotificationClient_DefaultDeviceChanged; _enumerator.UnregisterEndpointNotificationCallback(_notifyClient); _audioEndpointVolume.Dispose(); FreePlaybackDevice(); _enumerator.Dispose(); }
public void Dispose() { _enumerator.Dispose(); //if (Notifications != null) //{ // UnRegisterEndpointNotificationCallback((MMRenderNotificationClient)Notifications); //} }
private MMDevice GetPrimaryMicDevice() { var enumerator = new MMDeviceEnumerator(); var result = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications); enumerator.Dispose(); _tbIcon.Text = result.DeviceFriendlyName; return(result); }
public void CanAccessPropertyStore() { using (var enumerator = new MMDeviceEnumerator()) using (var collection = enumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.All)) { Utils.DumpCollection(collection); enumerator.Dispose(); collection.Dispose(); } }
public void Dispose() { if (_endpointVolumeCallback != null) { _endpointVolumeCallback.NotifyRecived -= VolumeNotifyReceived; } Stop(); _deviceEnumerator?.Dispose(); }
public void Dispose() { // Client up our MM objects in reverse order if (iAudioEndpointVolumeMixerCallback != null && iAudioEndpointVolume != null) { iAudioEndpointVolume.UnregisterControlChangeNotify(iAudioEndpointVolumeMixerCallback); } if (iAudioEndpointVolumeMixerCallback != null) { iAudioEndpointVolumeMixerCallback.NotifyRecived -= iVolumeChangedHandler; iAudioEndpointVolumeMixerCallback = null; } if (iAudioEndpointVolume != null) { iAudioEndpointVolume.Dispose(); iAudioEndpointVolume = null; } if (_mMdevice != null) { _mMdevice.Dispose(); _mMdevice = null; } if (iMultiMediaNotificationClient != null) { iMultiMediaNotificationClient.DefaultDeviceChanged -= iDefaultDeviceChangedHandler; iMultiMediaNotificationClient.Dispose(); iMultiMediaNotificationClient = null; } if (_mMdeviceEnumerator != null) { _mMdeviceEnumerator.Dispose(); _mMdeviceEnumerator = null; } Stop(); Close(); }
public void Dispose() { if (!_deviceEnumerator.IsDisposed) { _deviceEnumerator.Dispose(); } if (_audioMeter != null) { _audioMeter.Dispose(); _audioMeter = null; } }
private void EnumerateInputDevices() { Console.WriteLine("EnumerateInputDevices"); //create enumerator var enumerator = new MMDeviceEnumerator(); //cycle through all audio capture devices for (int i = 0; i < WaveIn.DeviceCount; i++) { Console.WriteLine($"<== {i} {enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active)[i]}"); } //clean up enumerator.Dispose(); }
private static AudioSessionManager2 GetDefaultAudioSessionManager2( DataFlow dataFlow) { using (MMDeviceEnumerator deviceEnumerator = new MMDeviceEnumerator()) { using (MMDevice defaultAudioEndpoint = deviceEnumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia)) { AudioSessionManager2 audioSessionManager2 = AudioSessionManager2.FromMMDevice(defaultAudioEndpoint); deviceEnumerator.Dispose(); defaultAudioEndpoint.Dispose(); return(audioSessionManager2); } } }
public void CanEnumerateCaptureDevices() { using (var enumerator = new MMDeviceEnumerator()) using (var collection = enumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.All)) { foreach (var item in collection) { Debug.WriteLine(item.ToString()); item.Dispose(); } enumerator.Dispose(); collection.Dispose(); } }
private MMDevice GetPrimaryMicDevice() { var enumerator = new MMDeviceEnumerator(); var result = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications); enumerator.Dispose(); _icon.Text = result.DeviceFriendlyName; if (PrimaryDevice is null || PrimaryDevice != result) { PrimaryDevice = result; } return(PrimaryDevice); }
private void Execute(ISender client, GetMicrophoneDevice message) { var deviceList = new List <Tuple <int, string> >(); var enumerator = new MMDeviceEnumerator(); for (int i = 0; i < WaveIn.DeviceCount; i++) { var deviceName = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active)[i].ToString(); deviceList.Add(Tuple.Create(i, deviceName)); } enumerator.Dispose(); client.Send(new GetMicrophoneDeviceResponse { DeviceInfos = deviceList }); }
// Form Loading private void Form1_Load(object sender, EventArgs e) { DisableDataForm(); // MMDevice Enumerator MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); // WaveOut Device (32 char limit) for (int i = 0; i < WaveOut.DeviceCount; i++) { // WaveOutCapabilities (32 char limit) WaveOutCapabilities woc = WaveOut.GetCapabilities(i); String deviceName = ""; // Using MMDevice foreach (MMDevice device in enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.All)) { if (device.FriendlyName.StartsWith(woc.ProductName)) { deviceName = device.FriendlyName; break; } } // No MMDevice Found so we use WaveOut one if (deviceName != "") { deviceComboBox.Items.Add(deviceName); } else { deviceComboBox.Items.Add(woc.ProductName); } } // Dispose enumerator.Dispose(); // Select Default One deviceComboBox.SelectedIndex = 0; // Start Hooking hooker.HotkeyDown += Hooker_HotkeyDown; startHooking(); }
public void Dispose() { try { Device.AudioEndpointVolume.OnVolumeNotification -= OnEndpointVolumeChanged; _deviceEnumerator.UnregisterEndpointNotificationCallback(this); } catch { } // Do disposal chains, each can throw try { _deviceEnumerator.Dispose(); } catch { } try { Device.Dispose(); } catch { } // Set to null _deviceEnumerator = null; Device = null; }
private void SetDeviceToAudio2() { var enumerator = new MMDeviceEnumerator(); var defaultrecordingdevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console); //https://www.codeproject.com/Articles/31836/Changing-your-Windows-audio-device-programmaticall if (!defaultrecordingdevice.FriendlyName.ToLower().Contains("cable output")) { //switch device LOL //ctrl+alt+f7 keybd_event(VK_LCONTROL, 0, 0, 0);// presses ctrl keybd_event(VK_MENU, 0, 0, 0); keybd_event(VK_F7, 0, 0, 0); keybd_event(VK_LCONTROL, 0, 2, 0);// presses ctrl keybd_event(VK_MENU, 0, 2, 0); keybd_event(VK_F7, 0, 2, 0); Thread.Sleep(2000); } enumerator.Dispose(); }
public MainForm() { InitializeComponent(); MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); var devicesIn = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active); enumerator.Dispose(); for (int i = 0; i < WaveIn.DeviceCount; i++) { waveInDict.Add(devicesIn[i].ID, i); } comboBoxDevices.Items.AddRange(devicesIn.ToArray()); if (comboBoxDevices.Items.Count == 0) { MessageBox.Show("No audio devices found!", "ERROR"); Application.Exit(); } String[] ports = SerialPort.GetPortNames(); comboBoxPort.Items.AddRange(ports); if (comboBoxPort.Items.Count == 0) { MessageBox.Show("No serial ports found!", "ERROR"); Application.Exit(); } LoadSettings(); timer.Interval = (int)Math.Round(numericUpDownRefreshRate.Value); sensitivity = (int)Math.Round(numericUpDownSensitivity.Value); al = new AudioListener((int)Math.Round(numericUpDownLowLimit.Value), (int)Math.Round(numericUpDownMidLimit.Value), BUFFERSIZE); if (Settings.Default.start) { ButtonStart_Click(null, null); } }
public float GetMicrophoneVolumeLevel() { float volume = 0.0f; MMDeviceEnumerator deviceEnumerator = (MMDeviceEnumerator)(new MMDeviceEnumerator()); foreach (MMDevice microphone in deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active)) { if (microphone.ID == this.MicrophoneId) { volume = microphone.AudioMeterInformation.MasterPeakValue; microphone.Dispose(); break; } else { microphone.Dispose(); } } deviceEnumerator.Dispose(); return(volume * 100); }
private void EnumerateOutputDevices() { Console.WriteLine("EnumerateOutputDevices"); //create enumerator var enumerator = new MMDeviceEnumerator(); //cycle trough all audio render devices for (int i = 0; i < WaveOut.DeviceCount; i++) { Console.WriteLine($"==> {i} {enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)[i]}"); } //clean up enumerator.Dispose(); Console.WriteLine("DirectSoundOut"); foreach (var dev in DirectSoundOut.Devices) { Console.WriteLine($"{dev.Guid} {dev.ModuleName} {dev.Description}"); } }
public List <List <string> > GetMicrophoneInfo() { /* return: * MMDevice.ID * MMDevice.FriendlyName * MMDevice.DeviceFriendlyName */ List <List <string> > microphoneInfo = new List <List <string> >(); MMDeviceEnumerator deviceEnumerator = (MMDeviceEnumerator)(new MMDeviceEnumerator()); foreach (MMDevice microphone in deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active)) { microphoneInfo.Add(new List <string> { microphone.ID, microphone.FriendlyName, microphone.DeviceFriendlyName }); microphone.Dispose(); } deviceEnumerator.Dispose(); return(microphoneInfo); }
internal override void Unload() { _deviceEnumerator?.Dispose(); _activeAudioDeviceManager?.Dispose(); _processMeterInformation?.Dispose(); }