private void Devices_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                var added            = ((IAudioDevice)e.NewItems[0]);
                var allExistingAdded = AllDevices.FirstOrDefault(d => d.Id == added.Id);
                if (allExistingAdded == null)
                {
                    AddDevice(added);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                var removed     = ((IAudioDevice)e.OldItems[0]).Id;
                var allExisting = AllDevices.FirstOrDefault(d => d.Id == removed);
                if (allExisting != null)
                {
                    AllDevices.Remove(allExisting);
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                AllDevices.Clear();
                foreach (var device in _deviceManager.Devices)
                {
                    AddDevice(device);
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #2
0
 private void DeviceManager_DefaultPlaybackDeviceChanged(object sender, IAudioDevice e)
 {
     if (e == null)
     {
         DefaultPlaybackDevice = null;
         DefaultPlaybackDeviceChanged?.Invoke(this, DefaultPlaybackDevice);
     }
     else
     {
         var dev = AllDevices.FirstOrDefault(d => d.Id == e.Id);
         if (dev != null)
         {
             DefaultPlaybackDevice = dev;
             DefaultPlaybackDeviceChanged?.Invoke(this, DefaultPlaybackDevice);
         }
     }
 }
Example #3
0
 private void OnDefaultChanged(object sender, IAudioDevice newDevice)
 {
     if (newDevice == null)
     {
         SetDefault(null);
     }
     else
     {
         var device = AllDevices.FirstOrDefault(d => d.Id == newDevice.Id);
         if (device == null)
         {
             AddDevice(newDevice);
             device = AllDevices.FirstOrDefault(d => d.Id == newDevice.Id);
         }
         SetDefault(device);
     }
 }
 private void DeviceManager_DefaultDeviceChanged(object sender, IAudioDevice e)
 {
     if (e == null)
     {
         SetDefault(null);
     }
     else
     {
         var dev = AllDevices.FirstOrDefault(d => d.Id == e.Id);
         if (dev == null)
         {
             AddDevice(e);
             dev = AllDevices.FirstOrDefault(d => d.Id == e.Id);
         }
         SetDefault(dev);
     }
 }
        private void DeviceManager_DefaultDeviceChanged(object sender, IAudioDevice e)
        {
            if (e == null)
            {
                Default = null;
                DefaultChanged?.Invoke(this, Default);
            }
            else
            {
                var dev = AllDevices.FirstOrDefault(d => d.Id == e.Id);
                if (dev == null)
                {
                    AddDevice(e);
                    dev = AllDevices.FirstOrDefault(d => d.Id == e.Id);
                }

                Default = dev;
                DefaultChanged?.Invoke(this, Default);
            }
        }