private static bool DeviceIsValid(IMultimediaDevice device) { try { string id; EDeviceState state; device.GetId(out id); device.GetState(out state); return(true); } catch { return(false); } }
private CoreAudioDevice CacheDevice(IMultimediaDevice mDevice) { if (!DeviceIsValid(mDevice)) { return(null); } string id; mDevice.GetId(out id); var device = GetDevice(id); if (device != null) { return(device); } device = new CoreAudioDevice(mDevice, this); device.StateChanged.Subscribe(OnAudioDeviceChanged); device.DefaultChanged.Subscribe(OnAudioDeviceChanged); device.PropertyChanged.Subscribe(OnAudioDeviceChanged); var lockAcquired = _lock.AcquireWriteLockNonReEntrant(); try { _deviceCache.Add(device); return(device); } finally { if (lockAcquired) { _lock.ExitWriteLock(); } } }