/// <summary> /// /// </summary> /// <param name="stateInfo"></param> private void Initialize(object stateInfo) { _stopping = false; bool success = false; try { _deviceEnumerator.RegisterEndpointNotificationCallback(this); success = true; } catch { } if (!success) { _deviceEnumerator = new MMDeviceEnumerator(); _deviceEnumerator.RegisterEndpointNotificationCallback(this); } foreach (var device in _deviceEnumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active)) { OnDeviceAdded(device); } foreach (var device in _devices.Values) { if (device.IsDefault) { OnDefaultDeviceChanged(device); } } _synchronizationContext.Post(o => ServiceStarted?.Invoke(this), null); }
private async Task <Result> StartAction(CancellationToken cancellationToken) { var result = await _origin.StartAsync(cancellationToken); if (result.Success) { ServiceStarted?.Invoke(this, _origin.Name); } return(result); }
/// <summary> /// /// </summary> /// <param name="stateInfo"></param> private void Initialize(object stateInfo) { _stopping = false; _deviceEnumerator.DeviceAdded += OnDeviceAdded; _deviceEnumerator.DeviceStateChanged += OnDeviceStateChanged; foreach (var device in _deviceEnumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.Active)) { OnDeviceAdded(device); } foreach (var device in _devices.Values) { if (device.IsDefault) { OnDefaultDeviceChanged(device); } } _synchronizationContext.Post(o => ServiceStarted?.Invoke(this), null); }
protected virtual void OnServiceStarted() { ServiceStarted?.Invoke(this, null); }