public void Open(int mixerIndex, bool isDigital) { lock (this) { if (isDigital) { _componentType = MixerComponentType.SourceWave; } // not enough to change this.. if (_mixerEventListener == null) { _mixerEventListener = new MixerEventListener(); _mixerEventListener.Start(); } _mixerEventListener.LineChanged += new MixerEventHandler(OnLineChanged); _mixerEventListener.ControlChanged += new MixerEventHandler(OnControlChanged); MixerNativeMethods.MixerControl mc = new MixerNativeMethods.MixerControl(); mc.Size = 0; mc.ControlId = 0; mc.ControlType = MixerControlType.Volume; mc.fdwControl = 0; mc.MultipleItems = 0; mc.ShortName = string.Empty; mc.Name = string.Empty; mc.Minimum = 0; mc.Maximum = 0; mc.Reserved = 0; IntPtr handle = IntPtr.Zero; if ( MixerNativeMethods.mixerOpen(ref handle, mixerIndex, _mixerEventListener.Handle, 0, MixerFlags.CallbackWindow) != MixerError.None) { throw new InvalidOperationException(); } _handle = handle; _mixerControlDetailsVolume = GetControl(_componentType, MixerControlType.Volume); _mixerControlDetailsMute = GetControl(_componentType, MixerControlType.Mute); _isMuted = (int)GetValue(_componentType, MixerControlType.Mute) == 1; _volume = (int)GetValue(_componentType, MixerControlType.Volume); } }
public void Open(int mixerIndex, bool isDigital) { lock (this) { _waveVolume = isDigital; if (isDigital) { _componentType = MixerComponentType.SourceWave; } else { _componentType = MixerComponentType.DestinationSpeakers; } // not enough to change this.. // Use Endpoint Volume API for Vista/Win7 if master volume is selected and always for Win8 to handle muting of master volume if ((OSInfo.OSInfo.VistaOrLater() && _componentType == MixerComponentType.DestinationSpeakers) || OSInfo.OSInfo.Win8OrLater()) { try { _audioDefaultDevice = new AEDev(); if (_audioDefaultDevice != null) { _audioDefaultDevice.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); _isMuted = _audioDefaultDevice.Muted; _volume = (int) Math.Round(_audioDefaultDevice.MasterVolume*VolumeMaximum); } } catch (Exception) { _isMuted = false; _volume = 100; } } // Use Windows Multimedia mixer functions for XP and for Vista and later if wave volume is selected if (_componentType == MixerComponentType.SourceWave || !OSInfo.OSInfo.VistaOrLater()) { if (_mixerEventListener == null) { _mixerEventListener = new MixerEventListener(); _mixerEventListener.Start(); } _mixerEventListener.LineChanged += new MixerEventHandler(OnLineChanged); _mixerEventListener.ControlChanged += new MixerEventHandler(OnControlChanged); MixerNativeMethods.MixerControl mc = new MixerNativeMethods.MixerControl(); mc.Size = 0; mc.ControlId = 0; mc.ControlType = MixerControlType.Volume; mc.fdwControl = 0; mc.MultipleItems = 0; mc.ShortName = string.Empty; mc.Name = string.Empty; mc.Minimum = 0; mc.Maximum = 0; mc.Reserved = 0; IntPtr handle = IntPtr.Zero; if ( MixerNativeMethods.mixerOpen(ref handle, mixerIndex, _mixerEventListener.Handle, 0, MixerFlags.CallbackWindow) != MixerError.None) { throw new InvalidOperationException(); } _handle = handle; _mixerControlDetailsVolume = GetControl(_componentType, MixerControlType.Volume); _mixerControlDetailsMute = GetControl(_componentType, MixerControlType.Mute); _isMuted = (int) GetValue(_componentType, MixerControlType.Mute) == 1; _volume = (int) GetValue(_componentType, MixerControlType.Volume); } } }
public void Open(int mixerIndex, bool isDigital) { lock (this) { if (isDigital) { _componentType = MixerComponentType.SourceWave; } else { _componentType = MixerComponentType.DestinationSpeakers; } // not enough to change this.. if (OSInfo.OSInfo.VistaOrLater() & (_componentType == MixerComponentType.DestinationSpeakers)) { _audioDefaultDevice = new AEDev(); _audioDefaultDevice.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); _isMuted = _audioDefaultDevice.Muted; _volume = (int)Math.Round(_audioDefaultDevice.MasterVolume * VolumeMaximum); return; } if (_mixerEventListener == null) { _mixerEventListener = new MixerEventListener(); _mixerEventListener.Start(); } _mixerEventListener.LineChanged += new MixerEventHandler(OnLineChanged); _mixerEventListener.ControlChanged += new MixerEventHandler(OnControlChanged); MixerNativeMethods.MixerControl mc = new MixerNativeMethods.MixerControl(); mc.Size = 0; mc.ControlId = 0; mc.ControlType = MixerControlType.Volume; mc.fdwControl = 0; mc.MultipleItems = 0; mc.ShortName = string.Empty; mc.Name = string.Empty; mc.Minimum = 0; mc.Maximum = 0; mc.Reserved = 0; IntPtr handle = IntPtr.Zero; if ( MixerNativeMethods.mixerOpen(ref handle, mixerIndex, _mixerEventListener.Handle, 0, MixerFlags.CallbackWindow) != MixerError.None) { throw new InvalidOperationException(); } _handle = handle; _mixerControlDetailsVolume = GetControl(_componentType, MixerControlType.Volume); _mixerControlDetailsMute = GetControl(_componentType, MixerControlType.Mute); _isMuted = (int)GetValue(_componentType, MixerControlType.Mute) == 1; _volume = (int)GetValue(_componentType, MixerControlType.Volume); } }
public void Open(int mixerIndex, bool isDigital, bool resetDevice = false) { try { lock (this) { using (MixerLock(lockInfinite)) { Log.Debug("Mixer: Open(), mixerIndex = {0}, isDigital = {1}, resetDevice = {2}", mixerIndex, isDigital, resetDevice); _useWave = isDigital; if (isDigital) { _componentType = MixerComponentType.SourceWave; } else { _componentType = MixerComponentType.DestinationSpeakers; } // Use Endpoint Volume API for Vista/Win7 if master volume is selected and always for Win8 to handle muting of master volume if ((OSInfo.OSInfo.VistaOrLater() && _componentType == MixerComponentType.DestinationSpeakers) || OSInfo.OSInfo.Win8OrLater()) { try { Log.Debug("Mixer: Open(), Endpoint Volume API for Master"); _audioDefaultDevice = new AEDev(resetDevice); if (_audioDefaultDevice != null) { _audioDefaultDevice.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); _isMuted = _audioDefaultDevice.Muted; _volume = (int)Math.Round(_audioDefaultDevice.MasterVolume * VolumeMaximum); } } catch (Exception ex) { Log.Error($"Mixer: Open(), Exception in Endpoint Volume API for Master: {ex}"); _isMuted = false; _volume = 100; } } else if (OSInfo.OSInfo.VistaOrLater() && _componentType == MixerComponentType.SourceWave) { try { Log.Debug("Mixer: Open(), Endpoint Volume API for Wave"); _audioDefaultDevice = new AEDev(resetDevice); if (_audioDefaultDevice != null) { _audioDefaultDevice.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); } } catch (Exception ex) { Log.Error($"Mixer: Open(), Exception in Endpoint Volume API for Wave: {ex}"); } } // Use Windows Multimedia mixer functions for XP and for Vista and later if wave volume is selected if (_componentType == MixerComponentType.SourceWave || !OSInfo.OSInfo.VistaOrLater()) { if (_mixerEventListener == null) { _mixerEventListener = new MixerEventListener(); _mixerEventListener.Start(); } _mixerEventListener.LineChanged += new MixerEventHandler(OnLineChanged); _mixerEventListener.ControlChanged += new MixerEventHandler(OnControlChanged); MixerNativeMethods.MixerControl mc = new MixerNativeMethods.MixerControl(); mc.Size = 0; mc.ControlId = 0; mc.ControlType = MixerControlType.Volume; mc.fdwControl = 0; mc.MultipleItems = 0; mc.ShortName = string.Empty; mc.Name = string.Empty; mc.Minimum = 0; mc.Maximum = 0; mc.Reserved = 0; IntPtr handle = IntPtr.Zero; if ( MixerNativeMethods.mixerOpen(ref handle, mixerIndex, _mixerEventListener.Handle, 0, MixerFlags.CallbackWindow) != MixerError.None) { throw new InvalidOperationException(); } _handle = handle; _mixerControlDetailsVolume = GetControl(_componentType, MixerControlType.Volume); _mixerControlDetailsMute = GetControl(_componentType, MixerControlType.Mute); _isMuted = (int)GetValue(_componentType, MixerControlType.Mute) == 1; _volume = (int)GetValue(_componentType, MixerControlType.Volume); _isMutedWave = _isMuted; _volumeWave = _volume; } } } } catch (Exception ex) { Log.Error($"Mixer: error occured in Open(): {ex}"); _isMuted = false; _volume = 100; } }
public void Open(int mixerIndex, bool isDigital) { lock (this) { if (isDigital) { _componentType = MixerComponentType.SourceWave; } // not enough to change this.. if (_mixerEventListener == null) { _mixerEventListener = new MixerEventListener(); _mixerEventListener.Start(); } _mixerEventListener.LineChanged += new MixerEventHandler(OnLineChanged); _mixerEventListener.ControlChanged += new MixerEventHandler(OnControlChanged); MixerNativeMethods.MixerControl mc = new MixerNativeMethods.MixerControl(); mc.Size = 0; mc.ControlId = 0; mc.ControlType = MixerControlType.Volume; mc.fdwControl = 0; mc.MultipleItems = 0; mc.ShortName = string.Empty; mc.Name = string.Empty; mc.Minimum = 0; mc.Maximum = 0; mc.Reserved = 0; IntPtr handle = IntPtr.Zero; if ( MixerNativeMethods.mixerOpen(ref handle, mixerIndex, _mixerEventListener.Handle, 0, MixerFlags.CallbackWindow) != MixerError.None) { throw new InvalidOperationException(); } _handle = handle; _mixerControlDetailsVolume = GetControl(_componentType, MixerControlType.Volume); _mixerControlDetailsMute = GetControl(_componentType, MixerControlType.Mute); _isMuted = (int)GetValue(_componentType, MixerControlType.Mute) == 1; _volume = (int)GetValue(_componentType, MixerControlType.Volume); } }
public void Open(int mixerIndex, bool isDigital) { lock (this) { if (isDigital) { _componentType = MixerComponentType.SourceWave; } else { _componentType = MixerComponentType.DestinationSpeakers; } // not enough to change this.. if (OSInfo.OSInfo.VistaOrLater() & (_componentType == MixerComponentType.DestinationSpeakers)) { _audioDefaultDevice = new AEDev(); _audioDefaultDevice.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); _isMuted = _audioDefaultDevice.Muted; _volume = (int)Math.Round(_audioDefaultDevice.MasterVolume * VolumeMaximum); return; } if (_mixerEventListener == null) { _mixerEventListener = new MixerEventListener(); _mixerEventListener.Start(); } _mixerEventListener.LineChanged += new MixerEventHandler(OnLineChanged); _mixerEventListener.ControlChanged += new MixerEventHandler(OnControlChanged); MixerNativeMethods.MixerControl mc = new MixerNativeMethods.MixerControl(); mc.Size = 0; mc.ControlId = 0; mc.ControlType = MixerControlType.Volume; mc.fdwControl = 0; mc.MultipleItems = 0; mc.ShortName = string.Empty; mc.Name = string.Empty; mc.Minimum = 0; mc.Maximum = 0; mc.Reserved = 0; IntPtr handle = IntPtr.Zero; if ( MixerNativeMethods.mixerOpen(ref handle, mixerIndex, _mixerEventListener.Handle, 0, MixerFlags.CallbackWindow) != MixerError.None) { throw new InvalidOperationException(); } _handle = handle; _mixerControlDetailsVolume = GetControl(_componentType, MixerControlType.Volume); _mixerControlDetailsMute = GetControl(_componentType, MixerControlType.Mute); _isMuted = (int)GetValue(_componentType, MixerControlType.Mute) == 1; _volume = (int)GetValue(_componentType, MixerControlType.Volume); } }