예제 #1
0
        private WaveInDevice[] _GetWaveInDevices()
        {
            try
            {
                int inDevicesCount = WaveIn.DeviceCount;
                MMDeviceCollection mmDeviceCollection = _enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);

                WaveInDevice[] waveInDevices = new WaveInDevice[inDevicesCount];

                for (int inDevice = 0; inDevice < inDevicesCount; inDevice++)
                {
                    var capabilities = WaveIn.GetCapabilities(inDevice);
                    //waveInDevices[inDevice] = new WaveInDevice(capabilities, inDevice);

                    //Getting full names of the devices.
                    foreach (MMDevice device in mmDeviceCollection)
                    {
                        if (device.FriendlyName.StartsWith(capabilities.ProductName))
                        {
                            waveInDevices[inDevice] = new WaveInDevice(capabilities, inDevice, device.FriendlyName);
                            break;
                        }
                    }
                }

                return(waveInDevices);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error occurred when getting wave in devices. {0}", ex.Message), ex);
            }
        }