Esempio n. 1
0
 private void AddDevice(string deviceId)
 {
     foreach (var soundOutMode in SoundOutModes.Where(x => x.Devices.All(y => y.Id != deviceId)))
     {
         ((SoundOutMode)soundOutMode).AddDevice(deviceId);
         UpdateWindowsDefault(soundOutMode);
     }
     CheckCurrentState();
 }
Esempio n. 2
0
        public void SetSoundOut(string soundOutMode, string id)
        {
            SoundOutType soundOutType;

            if (!Enum.TryParse(soundOutMode, out soundOutType))
            {
                return;
            }

            foreach (var device in SoundOutModes.SelectMany(x => x.Devices))
            {
                if (((SoundOutDevice)device).Type == soundOutType && device.Id == id)
                {
                    _currentSoundOutDevice = device;
                    return;
                }
            }
        }
Esempio n. 3
0
        private void LoadSoundOutModes()
        {
            SoundOutModes.Clear();
            using (var enumerator = new MMDeviceEnumerator())
            {
                MMDevice defaultDevice;
                try
                {
                    defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                }
                catch (CoreAudioAPIException)
                {
                    defaultDevice = null;
                }

                if (WasapiOut.IsSupportedOnCurrentPlatform)
                {
                    var wasApiMode = new SoundOutMode("WASAPI", SoundOutType.WasApi, GetWasApiSoundOutDeviceById, GetWasApiSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.WasApi));

                    using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                    {
                        foreach (var device in devices.Select(x => new SoundOutDevice(x.FriendlyName, x.DeviceID, SoundOutType.WasApi, defaultDevice != null && defaultDevice.DeviceID == x.DeviceID)))
                        {
                            wasApiMode.Devices.Add(device);
                        }
                    }

                    UpdateWindowsDefault(wasApiMode);
                    SoundOutModes.Add(wasApiMode);
                }

                var directSoundMode = new SoundOutMode("DirectSound", SoundOutType.DirectSound, GetDirectSoundOutDeviceById, GetDirectSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.DirectSound));
                foreach (var device in DirectSoundDeviceEnumerator.EnumerateDevices().Select(x => new SoundOutDevice(x.Description, x.Module, SoundOutType.DirectSound, defaultDevice != null && x.Description == defaultDevice.FriendlyName)))
                {
                    directSoundMode.Devices.Add(device);
                }

                UpdateWindowsDefault(directSoundMode);
                SoundOutModes.Add(directSoundMode);
                CheckCurrentState();
            }
        }
Esempio n. 4
0
        private void CheckCurrentState()
        {
            if (SoundOutModes.Any(x => x.Devices.Count > 0))
            {
                if (IsAvailable)
                {
                    return;
                }

                IsAvailable = true;
                Enable?.Invoke(this, EventArgs.Empty);
                return;
            }

            if (!IsAvailable)
            {
                return;
            }
            IsAvailable = false;
            Disable?.Invoke(this, EventArgs.Empty);
        }