public SoundDevice[] GetDevices() { // Create a DEVICE object to get device info WSSoundInterop.DEVICE device = new WSSoundInterop.DEVICE(); device.nMaxDesc = WSSoundInterop.WS_MAXNAMELEN; device.nMaxId = WSSoundInterop.WS_MAXNAMELEN; device.nMaxName = WSSoundInterop.WS_MAXNAMELEN; // Create device list to add devices into it during enumeration callbackDevices = new List <WSSoundInterop.DEVICE>(); // Enumerate devices int hr = WSSoundInterop.WSEnumDevices(this.pws, ref device, this.deviceCallback); if (hr != 0) { throw new SoundException("WSGetNumDevices", hr); } // Convert returned DEVICEs to SoundDevice int nDevices = callbackDevices.Count; SoundDevice[] soundDevices = new SoundDevice[nDevices]; for (int i = 0; i < nDevices; i++) { device = callbackDevices[i]; // Is device input or ouput (loopback) WSSoundInterop.DeviceType type = (WSSoundInterop.DeviceType)device.dwType; bool isLoopback = type == WSSoundInterop.DeviceType.Output; // Create Sound Device SoundDevice soundDevice = new SoundDevice(device.szId, device.szName, isLoopback, device.szDescription); soundDevices.SetValue(soundDevice, i); } callbackDevices.Clear(); return(soundDevices); }
public SoundDevice[] GetDevices() { // Create a DEVICE object to get device info WSSoundInterop.DEVICE device = new WSSoundInterop.DEVICE(); device.nMaxDesc = WSSoundInterop.WS_MAXNAMELEN; device.nMaxId = WSSoundInterop.WS_MAXNAMELEN; device.nMaxName = WSSoundInterop.WS_MAXNAMELEN; // Create device list to add devices into it during enumeration callbackDevices = new List<WSSoundInterop.DEVICE>(); // Enumerate devices int hr = WSSoundInterop.WSEnumDevices(this.pws, ref device, this.deviceCallback); if (hr != 0) { throw new SoundException("WSGetNumDevices", hr); } // Convert returned DEVICEs to SoundDevice int nDevices = callbackDevices.Count; SoundDevice[] soundDevices = new SoundDevice[nDevices]; for (int i = 0; i < nDevices; i++) { device = callbackDevices[i]; // Is device input or ouput (loopback) WSSoundInterop.DeviceType type = (WSSoundInterop.DeviceType)device.dwType; bool isLoopback = type == WSSoundInterop.DeviceType.Output; // Create Sound Device SoundDevice soundDevice = new SoundDevice(device.szId, device.szName, isLoopback, device.szDescription); soundDevices.SetValue(soundDevice, i); } callbackDevices.Clear(); return soundDevices; }
private bool EnumDevicesCallback(IntPtr pws, ref WSSoundInterop.DEVICE device) { callbackDevices.Add(device); return(true); }