public override async Task <bool> SetAsDefaultCommunicationsAsync(CancellationToken cancellationToken) { if (State != DeviceState.Active) { return(_isDefaultCommDevice = false); } var acquiredSemaphore = await _setDefaultCommSemaphore.AvailableWaitHandle.WaitOneAsync(0, cancellationToken); try { if (acquiredSemaphore) { _defaultCommResetEvent.Reset(); PolicyConfig.SetDefaultEndpoint(RealId, ERole.Communications); } await _defaultCommResetEvent.WaitOneAsync(cancellationToken); return(_isDefaultCommDevice); } catch (Exception ex) when(ex is OperationCanceledException || ex is TimeoutException) { throw new ComInteropTimeoutException(ex); } finally { if (acquiredSemaphore) { _setDefaultCommSemaphore.Release(); } } }
public override bool SetDefaultCommunicationsDevice(CoreAudioDevice dev) { if (dev == null) { return(false); } var oldDefault = dev.IsPlaybackDevice ? DefaultPlaybackCommunicationsDevice : DefaultCaptureCommunicationsDevice; try { PolicyConfig.SetDefaultEndpoint(dev.RealId, ERole.Communications); return(dev.IsDefaultCommunicationsDevice); } catch { return(false); } finally { //Raise the default changed event on the old device if (oldDefault != null && !oldDefault.IsDefaultCommunicationsDevice) { RaiseAudioDeviceChanged(new DefaultDeviceChangedEventArgs(oldDefault, true)); } } }
public override bool SetAsDefault(CancellationToken cancellationToken) { if (State != DeviceState.Active) { return(_isDefaultDevice = false); } var acquiredSemaphore = _setDefaultSemaphore.Wait(0, cancellationToken); try { if (acquiredSemaphore) { _defaultResetEvent.Reset(); PolicyConfig.SetDefaultEndpoint(RealId, ERole.Console | ERole.Multimedia); } _defaultResetEvent.WaitOne(cancellationToken); return(_isDefaultDevice); } catch (Exception ex) when(ex is OperationCanceledException || ex is TimeoutException) { throw new ComInteropTimeoutException(ex); } finally { if (acquiredSemaphore) { _setDefaultSemaphore.Release(); } } }
public override bool SetDefaultDevice(CoreAudioDevice dev) { if (dev == null) { return(false); } var oldDefault = dev.IsPlaybackDevice ? DefaultPlaybackDevice : DefaultCaptureDevice; try { if (IsNotVista()) { PolicyConfig.SetDefaultEndpoint(dev.RealId, ERole.Console | ERole.Multimedia); } else { PolicyConfigVista.SetDefaultEndpoint(dev.RealId, ERole.Console | ERole.Multimedia); } return(dev.IsDefaultDevice); } catch { return(false); } finally { //Raise the default changed event on the old device if (oldDefault != null && !oldDefault.IsDefaultDevice) { RaiseAudioDeviceChanged(new AudioDeviceChangedEventArgs(oldDefault, AudioDeviceEventType.DefaultDevice)); } } }