public static int GetVolume() { try { //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.Render, NAudio.CoreAudioApi.DeviceState.Active); //Loop through all devices foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { try { if (dev.State == NAudio.CoreAudioApi.DeviceState.Active) { float volume = dev.AudioEndpointVolume.MasterVolumeLevelScalar; int volumeInt = (int)(volume * 100); return volumeInt; } } catch (Exception ex) { //Do something with exception when an audio endpoint could not be muted Debug.WriteLine(dev.FriendlyName + " could not be muted with error " + ex); } } } catch (Exception ex) { //When something happend that prevent us to iterate through the devices Debug.WriteLine("Could not enumerate devices due to an excepion: " + ex.Message); } return -1; }
public IDeviceManualTriggerContext ManualTrigger(DeviceManualTriggerContextOption Option = null) { if (Option != null) { DeviceAddedEventHandler threadSafeEventHandler = DeviceAdded; SixtyBeatAudioDevice device = SixtyBeatAudioDevice.Create(Option.Tag as string); if (device != null) { threadSafeEventHandler?.Invoke(this, device); } return(null); } SixtyBeatAudioDeviceManualTriggerContext ResponseData = new SixtyBeatAudioDeviceManualTriggerContext(); ResponseData.Options = new List <DeviceManualTriggerContextOption>(); var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); //cycle through all audio devices for (int i = 0; i < WaveIn.DeviceCount; i++) { // these happen to enumate the same order NAudio.CoreAudioApi.MMDevice dev = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Capture, NAudio.CoreAudioApi.DeviceState.Active)[i]; string DeviceID = dev.Properties[new NAudio.CoreAudioApi.PropertyKey(DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Audio_InstanceId.fmtid, (int)DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Audio_InstanceId.pid)].Value.ToString(); if (!SixtyBeatAudioDevice.DeviceKnown(DeviceID)) { ResponseData.Options.Add(new DeviceManualTriggerContextOption(dev.FriendlyName, DeviceID)); } } enumerator.Dispose(); return(ResponseData); }
public static bool IsMuted() { try { //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.Render, NAudio.CoreAudioApi.DeviceState.Active); //Loop through all devices foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { try { if (dev.State == NAudio.CoreAudioApi.DeviceState.Active) { return(dev.AudioEndpointVolume.Mute); } } catch (Exception ex) { //Do something with exception when an audio endpoint could not be muted Debug.WriteLine(dev.FriendlyName + " could not be muted with error " + ex); } } } catch (Exception ex) { //When something happend that prevent us to iterate through the devices Debug.WriteLine("Could not enumerate devices due to an excepion: " + ex.Message); } return(false); }
public static void MuteChannel(int channelIndex, bool isMute, int delayMilliseconds = 0) { new Thread(() => { if (delayMilliseconds > 0) { Thread.Sleep(delayMilliseconds); } NAudio.CoreAudioApi.MMDeviceEnumerator mmde = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection devCol = mmde.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All); foreach (NAudio.CoreAudioApi.MMDevice dev in devCol) { try { if (dev.State == NAudio.CoreAudioApi.DeviceState.Active) { dev.AudioSessionManager.Sessions[dev.AudioSessionManager.Sessions.Count - channelIndex - 1].SimpleAudioVolume.Mute = isMute; } } catch { /* ignored */ } } }).Start(); }
public Array GetSourcesArray() { NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Capture, DeviceState.Active); return(devices.ToArray()); }
public Form1() { InitializeComponent(); NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active); comboBox1.Items.AddRange(devices.ToArray()); }
private void InitializeNAudio() { // Get all Audio devices in the system DeviceList = new List <NAudio.CoreAudioApi.MMDevice>(); NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active); DeviceList.AddRange(devices.ToArray()); }
public Form1() { InitializeComponent(); NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active); NAudio.CoreAudioApi.MMDeviceEnumerator devEnum = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDevice defaultDevice = devEnum.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Multimedia); comboBox1.Items.AddRange(devices.ToArray()); CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; }
public Form1() { InitializeComponent(); //Listing audio devices in comboBox1 NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active); comboBox1.Items.AddRange(devices.ToArray()); globalVariable.oldPeak = 0; //Trying to open a serial port. Program won't fail if Arduino is not connected. try { serialPort1.Open(); } catch { } }
public void SetVolumeNAudio(float volumeScalar) { try { NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active); foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { dev.AudioEndpointVolume.MasterVolumeLevelScalar = volumeScalar; } } catch (Exception ex) { System.Diagnostics.Debug.Print("Excepion: " + ex.Message); } }
public float GetVolumeNAudio() { try { NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active); foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { Console.WriteLine("Name of device: " + dev.FriendlyName); return(dev.AudioEndpointVolume.MasterVolumeLevelScalar); } } catch (Exception ex) { System.Diagnostics.Debug.Print("Excepion: " + ex.Message); } return(1.0f); }
public void ChangeVolume(int level) { NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All); foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { try { if (dev.State == NAudio.CoreAudioApi.DeviceState.Active) { var newVolume = (float)Math.Max(Math.Min(level, 100), 0) / (float)100; dev.AudioEndpointVolume.MasterVolumeLevelScalar = newVolume; dev.AudioEndpointVolume.Mute = level == 0; } } catch (Exception) {} } }
public Form1() { InitializeComponent(); trackBar1.ValueChanged += trackBar1_ValueChanged; try { //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 { dev.AudioEndpointVolume.MasterVolumeLevel = 0; Trace.WriteLine("MasterVolumeLevel:" + dev.AudioEndpointVolume.StepInformation.StepCount); trackBar1.Minimum = (int)dev.AudioEndpointVolume.VolumeRange.MinDecibels; trackBar1.Maximum = (int)dev.AudioEndpointVolume.VolumeRange.MaxDecibels; trackBar1.Scale(dev.AudioEndpointVolume.MasterVolumeLevelScalar); trackBar1.Value = (int)dev.AudioEndpointVolume.MasterVolumeLevel; //Set at maximum volume //dev.AudioEndpointVolume.MasterVolumeLevel = 0; //Get its audio volume System.Diagnostics.Debug.Print("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevel.ToString()); //Mute it //dev.AudioEndpointVolume.Mute = true; System.Diagnostics.Debug.Print(dev.FriendlyName + " is muted"); } catch (Exception ex) { //Do something with exception when an audio endpoint could not be muted System.Diagnostics.Debug.Print(dev.FriendlyName + " could not be muted"); } } } catch (Exception ex) { //When something happend that prevent us to iterate through the devices System.Diagnostics.Debug.Print("Could not enumerate devices due to an excepion: " + ex.Message); } }
public static void SetVolume(int level) { try { //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.Render, NAudio.CoreAudioApi.DeviceState.Active); //Loop through all devices foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { try { if (dev.State == NAudio.CoreAudioApi.DeviceState.Active) { var newVolume = (float)Math.Max(Math.Min(level, 100), 0) / (float)100; //Set at maximum volume dev.AudioEndpointVolume.MasterVolumeLevelScalar = newVolume; //dev.AudioEndpointVolume.Mute = level == 0; //Get its audio volume Debug.WriteLine("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevelScalar.ToString()); } else { Debug.WriteLine("Ignoring device " + dev.FriendlyName + " with state " + dev.State); } } catch (Exception ex) { //Do something with exception when an audio endpoint could not be muted Debug.WriteLine(dev.FriendlyName + " could not be muted with error " + ex); } } } catch (Exception ex) { //When something happend that prevent us to iterate through the devices Debug.WriteLine("Could not enumerate devices due to an excepion: " + ex.Message); } }
public void SetVolume(int level) { try { //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 { if (dev.State == NAudio.CoreAudioApi.DeviceState.Active) { var newVolume = (float)Math.Max(Math.Min(level, 100), 0) / (float)100; //Set at maximum volume dev.AudioEndpointVolume.MasterVolumeLevelScalar = newVolume; dev.AudioEndpointVolume.Mute = level == 0; //Get its audio volume Console.WriteLine("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevelScalar.ToString()); } else { Console.WriteLine("Ignoring device " + dev.FriendlyName + " with state " + dev.State); } } catch (Exception ex) { //Do something with exception when an audio endpoint could not be muted Console.WriteLine(dev.FriendlyName + " could not be muted with error " + ex); } } } catch (Exception ex) { //When something happend that prevent us to iterate through the devices Console.WriteLine("Could not enumerate devices due to an excepion: " + ex.Message); } }
public static List <string> GetDeviceList() { NAudio.CoreAudioApi.MMDeviceEnumerator enu = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var devices = enu.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active); List <string> ret = new List <string>(); foreach (var d in devices) { try { ret.Add(d.FriendlyName); } catch (Exception exc) { } } ret.Sort(); return(ret); }
public int GetValueVolume() { int volume = 0; NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All); foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { try { if (dev.State == NAudio.CoreAudioApi.DeviceState.Active) { volume = Convert.ToInt32(dev.AudioEndpointVolume.MasterVolumeLevelScalar * 100); } } catch (Exception) { } } return(volume); }
private void GetDevice() { listBox1.Items.Add("GetDevice"); try { //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 { if (dev.State == NAudio.CoreAudioApi.DeviceState.Active) { listBox1.Items.Add("Device 찾음"); listBox1.Items.Add(dev.FriendlyName); cbDevice.Items.Add(dev); } else { Console.WriteLine("Ignoring device " + dev.FriendlyName + " with state " + dev.State); } } catch (Exception ex) { listBox1.Items.Add(ex.ToString()); } } } catch (Exception ex) { listBox1.Items.Add(ex.ToString()); } if (cbDevice.Items.Count > 0) { cbDevice.SelectedIndex = 0; master = (NAudio.CoreAudioApi.MMDevice)cbDevice.Items[0]; } }
public void setSystemVolume(float vol) { try { NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All); foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { try { //System.Diagnostics.Debug.Print(dev.FriendlyName); dev.AudioEndpointVolume.MasterVolumeLevelScalar = vol; break; } catch { } } } catch { } }
private void buttonDown_Click(object sender, EventArgs e) { try { //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 { dev.AudioEndpointVolume.VolumeStepDown(); Trace.WriteLine(dev.AudioEndpointVolume.MasterVolumeLevel); trackBar1.Value = (int)dev.AudioEndpointVolume.MasterVolumeLevel; //Trace.WriteLine(trackBar1.Value); //Set at maximum volume //dev.AudioEndpointVolume.MasterVolumeLevel = 0; //Get its audio volume System.Diagnostics.Debug.Print("Volume of " + dev.FriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevel.ToString()); //Mute it //dev.AudioEndpointVolume.Mute = true; System.Diagnostics.Debug.Print(dev.FriendlyName + " is muted"); } catch (Exception ex) { //Do something with exception when an audio endpoint could not be muted System.Diagnostics.Debug.Print(dev.FriendlyName + " could not be muted"); } } } catch (Exception ex) { //When something happend that prevent us to iterate through the devices System.Diagnostics.Debug.Print("Could not enumerate devices due to an excepion: " + ex.Message); } }
public void SetVolume(Int32 iLevel) { Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.info, "Attempting tomute the volume of all connected audio devices."); try { NAudio.CoreAudioApi.MMDeviceEnumerator pMDEEnum = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection pMDCDevices = pMDEEnum.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All); foreach (NAudio.CoreAudioApi.MMDevice curDevice in pMDCDevices) { try { if (curDevice.State == NAudio.CoreAudioApi.DeviceState.Active) { float pFltNewVolume = (float)Math.Max(Math.Min(iLevel, 100), 0) / (float)100; curDevice.AudioEndpointVolume.MasterVolumeLevelScalar = pFltNewVolume; curDevice.AudioEndpointVolume.Mute = (iLevel == 0); Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.info, "Volume of {0} is {1}.", curDevice.FriendlyName, curDevice.AudioEndpointVolume.MasterVolumeLevelScalar.ToString()); } else { Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.debug, "Ignoring device {0} with state {1}.", curDevice.FriendlyName, curDevice.State); } } catch (Exception ex) { Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.error, "{0} could not be muted.", curDevice.FriendlyName); Program.Logger.WriteException(ex); } } } catch (Exception ex) { Program.Logger.WriteLine(Debugging.BasicTextLogger.MessageType.error, "Unable to enumerate audio devices."); Program.Logger.WriteException(ex); } }
public void GetAudioDevices() { NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection devices = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All); try { foreach (NAudio.CoreAudioApi.MMDevice dev in devices) { try { bool mute = dev.AudioEndpointVolume.Mute; System.Diagnostics.Debug.Print("Device {0} mute value: {1} ", dev.FriendlyName, mute); audioDevices[dev] = mute; } catch { } } } catch { } }
private void SourceStreamDataAvailable(object sender, WaveInEventArgs e) { NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active); NAudio.CoreAudioApi.MMDevice device = DevCol[3]; double volume = Math.Round(device.AudioMeterInformation.MasterPeakValue * 100, 1); Console.WriteLine(volume.ToString()); if (waveWriter == null) { return; } if (volume < 1) { counter++; } else { waveWriter.Write(e.Buffer, 0, e.BytesRecorded); waveWriter.Flush(); counter = 0; mCounter++; } if (counter > 30) { long a1 = sw.ElapsedMilliseconds; int c = mCounter; counter = 0; sourceStream.DataAvailable -= this.SourceStreamDataAvailable; StopRecording(); eventStopRecording(this, new EventArgs()); } }
public override void Process(StreamDeckSharp.IStreamDeck deck) { if (baseBitMap == null) { baseBitMap = (Bitmap)Bitmap.FromFile("Speaker.bmp"); } Bitmap tempBitmap = new Bitmap(baseBitMap.Width, baseBitMap.Height); if (dev == null) { NAudio.CoreAudioApi.MMDeviceEnumerator enu = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var devices = enu.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.All); foreach (var d in devices) { try { if (d.FriendlyName == OutputDeviceName) { dev = d; break; } } catch (Exception exc) { } } } if (dev != null) { try { //"XSplit Stream Audio Renderer") { if (base.enabled) { int pct = (int)(Math.Round(dev.AudioMeterInformation.MasterPeakValue * 100)); Console.Write(""); System.Drawing.Brush GreenPen = new SolidBrush(Color.Green); System.Drawing.Brush YellowPen = new SolidBrush(Color.Yellow); System.Drawing.Brush RedPen = new SolidBrush(Color.Red); using (var graph = Graphics.FromImage(tempBitmap)) { graph.DrawImage(baseBitMap, 0, 0); int properWith = 72 * pct / 100; if (pct > 95) { graph.FillRectangle(RedPen, 0, 0, properWith, 72 - 0); } else { if (pct > 75) { graph.FillRectangle(YellowPen, 0, 0, properWith, 72 - 0); } else { graph.FillRectangle(GreenPen, 0, 0, properWith, 72 - 0); } } } theBitmap = tempBitmap; } } } catch (Exception exc) { } } }
public void SetVolume(int value) { NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active); foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { var sessions = dev.AudioSessionManager.Sessions; for(int i = 0; i < sessions.Count; i++) { Process process = Process.GetProcessById((int)sessions[i].GetProcessID); if (process.ProcessName == "Spotify") { sessions[i].SimpleAudioVolume.Mute = (value > 0) ? false : true; } } } }
public void UpdateDeviceInfo() { inDeviceInfo = new List<DeviceInfo>(); outDeviceInfo = new List<DeviceInfo>(); // Get devices for in and out List<WaveInCapabilities> inDevCaps = new List<WaveInCapabilities>(); int waveInDevices = WaveIn.DeviceCount; for (int waveInDevice = 0; waveInDevice < waveInDevices; waveInDevice++) { WaveInCapabilities devCaps = WaveIn.GetCapabilities(waveInDevice); inDevCaps.Add(devCaps); logger.Info("AudioDevices::UpdateDeviceInfo Device {0}: {1}, {2} channels", waveInDevice, devCaps.ProductName, devCaps.Channels); } List<WaveOutCapabilities> outDevCaps = new List<WaveOutCapabilities>(); int waveOutDevices = WaveOut.DeviceCount; for (int waveOutDevice = 0; waveOutDevice < waveOutDevices; waveOutDevice++) { WaveOutCapabilities devCaps = WaveOut.GetCapabilities(waveOutDevice); outDevCaps.Add(devCaps); logger.Info("AudioDevices::UpdateDeviceInfo Device {0}: {1}, {2} channels", waveOutDevice, devCaps.ProductName, devCaps.Channels); } // Now go through MM devices to match up try { //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 { for (int idx = 0; idx < inDevCaps.Count; idx++) if (DevicesMatch(inDevCaps[idx].ProductName, dev.FriendlyName)) { DeviceInfo devInfo = new DeviceInfo(); devInfo.waveDeviceNumber = idx; devInfo.deviceName = dev.FriendlyName; devInfo.deviceId = dev.ID; devInfo.waveInCaps = inDevCaps[idx]; inDeviceInfo.Add(devInfo); if (_curInDevice == null) { _curInDevice = dev; _curWaveInDeviceInfoIdx = inDeviceInfo.Count - 1; } } for (int idx = 0; idx < outDevCaps.Count; idx++) if (DevicesMatch(outDevCaps[idx].ProductName, dev.FriendlyName)) { DeviceInfo devInfo = new DeviceInfo(); devInfo.waveDeviceNumber = idx; devInfo.deviceName = dev.FriendlyName; devInfo.deviceId = dev.ID; devInfo.waveOutCaps = outDevCaps[idx]; outDeviceInfo.Add(devInfo); bool bUseThis = false; if (_curOutDevice == null) bUseThis = true; else if (!_curOutDevice.FriendlyName.Contains("Speakers") && dev.FriendlyName.Contains("Speakers")) bUseThis = true; if (bUseThis) { _curOutDevice = dev; _curWaveOutDeviceInfoIdx = outDeviceInfo.Count - 1; } } } catch (Exception ex) { //Do something with exception when an audio endpoint could not be muted logger.Error("AudioDevices::UpdateDeviceInfo Exception in Update {0}", ex.Message); } } } catch (Exception ex) { //When something happend that prevent us to iterate through the devices logger.Error("AudioDevices::UpdateDeviceInfo Could not enumerate devices due to an excepion: {0}", ex.Message); } }
private void mute(bool flag) { try { NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All); foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol) { try { //System.Diagnostics.Debug.Print(dev.FriendlyName); //TODO: Understand dev.AudioEndpointVolume.Mute = flag; } catch { } } } catch { } }
public void init() { List <LSDevice> ldev = new List <LSDevice>(); try { NAudio.CoreAudioApi.MMDeviceEnumerator mde = new NAudio.CoreAudioApi.MMDeviceEnumerator(); Logger.app.a("Created MM enumerator"); try { foreach ( NAudio.CoreAudioApi.MMDevice device in mde.EnumerateAudioEndPoints( NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All)) { try { LSDevice add = new LSDevice(); add.mm = device; add.isRec = device.DataFlow == NAudio.CoreAudioApi.DataFlow.Capture; add.isPlay = device.DataFlow == NAudio.CoreAudioApi.DataFlow.Render; if (device.DataFlow == NAudio.CoreAudioApi.DataFlow.All) { add.isRec = add.isPlay = true; } Logger.app.a("Df " + add.isPlay + " " + add.isRec); add.id = device.ID; Logger.app.a("ID " + add.id); add.name = device.ToString(); Logger.app.a("Na " + add.name); ldev.Add(add); } catch { Logger.app.a("Failed !"); } } } catch { Logger.app.a("Failed !!"); } } catch { Logger.app.a("Failed !!!"); } devs = ldev.ToArray(); if (string.IsNullOrEmpty(s_devRec)) { s_devRec = ""; } if (string.IsNullOrEmpty(s_devMic)) { s_devMic = ""; } if (string.IsNullOrEmpty(s_devOut)) { s_devOut = ""; } if (!string.IsNullOrEmpty(s_devRec)) { devRec = getDevByID(s_devRec); // ?? devs.First(x => x.isPlay); } if (!string.IsNullOrEmpty(s_devMic)) { devMic = getDevByID(s_devMic); } if (!string.IsNullOrEmpty(s_devOut)) { devOut = getDevByID(s_devOut); } }
public override CommandFeedback Execute(string[] args) { string strIP = args[1]; string audioOutput = args[2]; NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var audioDevices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active); var audioDevice = audioDevices.FirstOrDefault(c => c.FriendlyName.ToLower().Contains(audioOutput)); if (audioDevice == null) { ConsoleU.WriteLine("Failed to locate audio device", ConsoleColor.Red); return(CommandFeedback.Error); } //WasapiLoopbackCapture capture = new WasapiLoopbackCapture(); //capture.DataAvailable += (object s, WaveInEventArgs waveArgs) => { // //writer.Write(a.Buffer, 0, a.BytesRecorded); // //if (writer.Position > capture.WaveFormat.AverageBytesPerSecond * 20) { // // capture.StopRecording(); // //} //}; Device device = new Device(strIP); AsyncHelpers.RunSync(device.Connect); int lastBrightness = 1; AsyncHelpers.RunSync(() => { for (; ;) { Thread.Sleep(TimeSpan.FromMilliseconds(1001)); float peakValue = audioDevice.AudioMeterInformation.MasterPeakValue; int peakValueCent = (int)(peakValue * 120); int peakValueBars = (int)(peakValue * 120); int peakValueInt = (int)(peakValue * 200.0f); peakValueCent = MathUtil.Clamp(peakValueCent, 1, 100); //Math.Log() //device.SetBrightness((int)(audioDevice.AudioMeterInformation.MasterPeakValue * 200)); //AsyncHelpers.RunSync(() => { // return device.SetRGBColor(peakValueInt / 2, peakValueInt / 2, peakValueInt); //}); if (lastBrightness != peakValueCent) { lastBrightness = peakValueCent; AsyncHelpers.RunSync(() => { return(device.SetBrightness(peakValueCent)); }); } string strRepeat = StringUtil.RepeatCharacter('■', peakValueBars); Console.WriteLine($"({peakValueCent}) {strRepeat}"); //Console.WriteLine(peakValueInt); } }); device.Disconnect(); return(CommandFeedback.Success); }
public void init() { List<LSDevice> ldev = new List<LSDevice>(); try { NAudio.CoreAudioApi.MMDeviceEnumerator mde = new NAudio.CoreAudioApi.MMDeviceEnumerator(); Logger.app.a("Created MM enumerator"); try { foreach ( NAudio.CoreAudioApi.MMDevice device in mde.EnumerateAudioEndPoints( NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All)) { try { LSDevice add = new LSDevice(); add.mm = device; add.isRec = device.DataFlow == NAudio.CoreAudioApi.DataFlow.Capture; add.isPlay = device.DataFlow == NAudio.CoreAudioApi.DataFlow.Render; if (device.DataFlow == NAudio.CoreAudioApi.DataFlow.All) { add.isRec = add.isPlay = true; } Logger.app.a("Df " + add.isPlay + " " + add.isRec); add.id = device.ID; Logger.app.a("ID " + add.id); add.name = device.ToString(); Logger.app.a("Na " + add.name); ldev.Add(add); } catch { Logger.app.a("Failed !"); } } } catch { Logger.app.a("Failed !!"); } } catch { Logger.app.a("Failed !!!"); } devs = ldev.ToArray(); if (string.IsNullOrEmpty(s_devRec)) s_devRec = ""; if (string.IsNullOrEmpty(s_devMic)) s_devMic = ""; if (string.IsNullOrEmpty(s_devOut)) s_devOut = ""; if (!string.IsNullOrEmpty(s_devRec)) devRec = getDevByID(s_devRec); // ?? devs.First(x => x.isPlay); if (!string.IsNullOrEmpty(s_devMic)) devMic = getDevByID(s_devMic); if (!string.IsNullOrEmpty(s_devOut)) devOut = getDevByID(s_devOut); }
private void InitializeNAudio() { // Get all Audio devices in the system DeviceList = new List<NAudio.CoreAudioApi.MMDevice>(); NAudio.CoreAudioApi.MMDeviceEnumerator enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator(); var devices = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.Active); DeviceList.AddRange(devices.ToArray()); }