예제 #1
0
        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;
        }
예제 #2
0
        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;
        }
예제 #3
0
        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;
        }
예제 #4
0
        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;
        }
예제 #5
0
파일: Core.cs 프로젝트: catright/Wale
 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);
 }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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();
        }