private void DeviceAdded(string devID) { if (InvokeRequired) { BeginInvoke(new DevEventDelegate(DeviceAdded), devID); } else { if (listDevices.Items.Cast <ListViewItem>().Any(item => (string)item.Tag == devID)) { return; } var pDevices = EndPoints.DeviceEnumerator.EnumerateAudioEndPoints(RenderType, EDeviceState.Active); if (pDevices.Count > 0) { for (var i = 0; i < pDevices.Count; i++) { if (pDevices[i].ID == devID) { if (listDevices.Items.Cast <ListViewItem>().Any(item => (string)item.Tag == devID)) { return; } var device = pDevices[i]; DeviceIcons.Add(device.IconPath); var devSettings = Program.settings.Device.Find(x => x.DeviceID == devID); if (devSettings == null || !devSettings.HideFromList) { var item = new ListViewItem { ImageIndex = listDevices.Items.Count, Text = device.FriendlyName, Tag = devID, }; listDevices.Items.Add(item); } listDevices.Sort(); SetSizes(); } } } } }
private void RefreshDevices(EDataFlow renderType) { listDevices.Clear(); DeviceIcons.Clear(); listDevices.BeginUpdate(); var pDevices = EndPoints.DeviceEnumerator.EnumerateAudioEndPoints(renderType, EDeviceState.Active); if (pDevices.Count > 0) { var defaultDev = EndPoints.DeviceEnumerator.GetDefaultAudioEndpoint(renderType, ERole.eMultimedia).ID; var devCount = pDevices.Count; for (var i = 0; i < devCount; i++) { var device = pDevices[i]; var devID = device.ID; DeviceIcons.Add(device.IconPath); var devSettings = Program.settings.Device.Find(x => x.DeviceID == devID); if (devSettings == null || !devSettings.HideFromList) { var item = new ListViewItem { ImageIndex = i, Text = device.FriendlyName, Selected = devID == defaultDev, Tag = devID, }; listDevices.Items.Add(item); if (devID == defaultDev) { SetDeviceIcon(i, true); SetTrayIcons(); } } } } listDevices.EndUpdate(); }