public void Dispose() { if (_deviceEnumerator != null) { _deviceEnumerator.DefaultDeviceChanged -= OnDefaultDeviceChanged; _deviceEnumerator.DeviceRemoved -= OnDeviceRemoved; _deviceEnumerator.DeviceStateChanged -= OnDeviceStateChanged; } if (_callback != null) { _callback.NotifyRecived -= OnEndpointVolumeChanged; } if (_endpointVolume != null) { _endpointVolume.UnregisterControlChangeNotify(_callback); } _deviceEnumerator = null; _endpointVolume = null; _callback = null; Device = null; }
public void Dispose() { foreach (var session in _sessions.Values) { session.SessionEnded -= OnSessionEnded; session.VolumeChanged -= OnSessionVolumeChanged; session.Dispose(); } _sessions.Clear(); _callback.NotifyRecived -= OnEndpointVolumeChanged; _sessionManager.SessionCreated -= OnSessionCreated; _endpointVolume?.UnregisterControlChangeNotify(_callback); _endpointVolume?.Dispose(); _endpointVolume = null; _callback = null; _sessionManager?.Dispose(); _sessionManager = null; _device?.Dispose(); _device = null; }
public void Dispose() { try { // Do unregistration, can throw if (_deviceEnumerator != null) { _deviceEnumerator.DefaultDeviceChanged -= OnDefaultDeviceChanged; _deviceEnumerator.DeviceRemoved -= OnDeviceRemoved; _deviceEnumerator.DeviceStateChanged -= OnDeviceStateChanged; } if (_callback != null) { _callback.NotifyRecived -= OnEndpointVolumeChanged; } if (_endpointVolume != null) { _endpointVolume.UnregisterControlChangeNotify(_callback); } } catch { } // Do disposal chains, each can throw try { _deviceEnumerator.Dispose(); } catch { } try { Device.Dispose(); } catch { } // Set to null _deviceEnumerator = null; _endpointVolume = null; _callback = null; Device = null; }
public void Stop() { if (!IsRunning) { return; } _logger.Info("Stopping audio engine"); _deviceEnumerator.DefaultDeviceChanged -= DefaultDeviceChanged; _endpointVolumeCallback.NotifyRecived -= VolumeNotifyReceived; _endpointVolume?.UnregisterControlChangeNotify(_endpointVolumeCallback); _endpointVolume?.Dispose(); _logger.Info($"Disposing modules ({_modules?.Count ?? 0})"); if (_modules?.Count > 0) { foreach (var audioModule in _modules) { _logger.Info($"Disposing module {audioModule.Id} ({audioModule.GetType()})"); audioModule.Dispose(); } _modules.Clear(); } _logger.Info("Audio engine stopped"); IsRunning = false; }
private void UnloadMMD() { M.D(1900, "UnloadMMD"); AMI.Dispose(); AEVC.NotifyRecived -= AEV_NotifyRecived; AEV.UnregisterControlChangeNotify(AEVC); AEV.Dispose(); L.MMD.Dispose(); L.MMD = null; L.MSD = null; M.D(1909); }
private void SetupDefaultEndpoint() { if (_endpointVolume != null) { _endpointVolume.UnregisterControlChangeNotify(_endpointVolumeCallback); _endpointVolume.Dispose(); } try { var defaultDevice = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); _endpointVolume = AudioEndpointVolume.FromDevice(defaultDevice); _endpointVolume.RegisterControlChangeNotify(_endpointVolumeCallback); } catch (Exception ex) { _logger.Error(ex); } }
public void Dispose() { // Client up our MM objects in reverse order if (iAudioEndpointVolumeMixerCallback != null && iAudioEndpointVolume != null) { iAudioEndpointVolume.UnregisterControlChangeNotify(iAudioEndpointVolumeMixerCallback); } if (iAudioEndpointVolumeMixerCallback != null) { iAudioEndpointVolumeMixerCallback.NotifyRecived -= iVolumeChangedHandler; iAudioEndpointVolumeMixerCallback = null; } if (iAudioEndpointVolume != null) { iAudioEndpointVolume.Dispose(); iAudioEndpointVolume = null; } if (_mMdevice != null) { _mMdevice.Dispose(); _mMdevice = null; } if (iMultiMediaNotificationClient != null) { iMultiMediaNotificationClient.DefaultDeviceChanged -= iDefaultDeviceChangedHandler; iMultiMediaNotificationClient.Dispose(); iMultiMediaNotificationClient = null; } if (_mMdeviceEnumerator != null) { _mMdeviceEnumerator.Dispose(); _mMdeviceEnumerator = null; } Stop(); Close(); }