Пример #1
0
        public static IEnumerable <IDeviceInfo> EnumerateAvailableDevices()
        {
            if (CacheList != null)
            {
                foreach (var deviceInfo in CacheList)
                {
                    yield return(deviceInfo);
                }

                yield break;
            }

            CacheList = new List <IDeviceInfo> {
                WasapiInfo.Default
            };
            yield return(WasapiInfo.Default);

            for (int n = -1; n < WaveOut.DeviceCount; n++)
            {
                WaveOutInfo info = null;
                try
                {
                    var caps = WaveOut.GetCapabilities(n);
                    info = new WaveOutInfo(caps.ProductName, n);
                }
                catch (Exception ex)
                {
                    Logger.Error("Error while enumerating WaveOut device: {0}", ex.Message);
                }

                if (info != null)
                {
                    CacheList.Add(info);
                    yield return(info);
                }
            }

            foreach (var dev in DirectSoundOut.Devices)
            {
                DirectSoundOutInfo info = null;
                try
                {
                    info = new DirectSoundOutInfo(dev.Description, dev.Guid);
                }
                catch (Exception ex)
                {
                    Logger.Error("Error while enumerating DirectSoundOut device: {0}", ex.Message);
                }

                if (info != null)
                {
                    CacheList.Add(info);
                    yield return(info);
                }
            }

            foreach (var wasapi in MMDeviceEnumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.All))
            {
                WasapiInfo info = null;
                try
                {
                    if (wasapi.DataFlow != DataFlow.Render || wasapi.State != DeviceState.Active)
                    {
                        continue;
                    }
                    info = new WasapiInfo(wasapi.FriendlyName, wasapi.ID)
                    {
                        Device = wasapi
                    };
                }
                catch (Exception ex)
                {
                    Logger.Error("Error while enumerating WASAPI device: {0}", ex.Message);
                }

                if (info != null)
                {
                    CacheList.Add(info);
                    yield return(info);
                }
            }

            foreach (var asio in AsioOut.GetDriverNames())
            {
                AsioOutInfo info = null;
                try
                {
                    info = new AsioOutInfo(asio);
                }
                catch (Exception ex)
                {
                    Logger.Error("Error while enumerating ASIO device: {0}", ex.Message);
                }

                if (info != null)
                {
                    CacheList.Add(info);
                    yield return(info);
                }
            }
        }
Пример #2
0
 protected bool Equals(DirectSoundOutInfo other)
 {
     return(FriendlyName == other.FriendlyName && DeviceGuid.Equals(other.DeviceGuid));
 }