public MainWindow() { InitializeComponent(); _interceptor.Initialize(); _interceptor.AddCallback(OnKeyAction); // Get the active microphone and speakers MMDeviceEnumerator deviceEnumerator = new MMDeviceEnumerator(); MMDeviceCollection micList = deviceEnumerator.EnumerateAudioEndPoints(EDataFlow.eCapture, EDeviceState.DEVICE_STATE_ACTIVE); MMDeviceCollection speakerList = deviceEnumerator.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE); _activeSpeaker = deviceEnumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia); _volumeRange = _activeSpeaker.AudioEndpointVolume.VolumeRange; _normalSpeakerVolume = _activeSpeaker.AudioEndpointVolume.MasterVolumeLevel; // ?? TODO: Add support for selecting applications that when their audio is above a certain level, turn down the audio of other applications. //DevicePeriod dp = _activeSpeaker.DevicePeriod; //Console.WriteLine(dp.DefaultPeriod); //Console.WriteLine(dp.MinimumPeriod); for (int i = 0; i < micList.Count; i++) { MMDevice mic = micList[i]; _microphones.Add(mic); Console.WriteLine("Found microphone: " + mic.FriendlyName + " " + mic.ID); } for (int i = 0; i < speakerList.Count; i++) { MMDevice speaker = speakerList[i]; _speakers.Add(speaker); Console.WriteLine("Found speaker: " + speaker.FriendlyName + " " + speaker.ID); } MinimizeToTray.Initialize(this, _muteIcon); }
internal AudioEndpointVolume(IAudioEndpointVolume realEndpointVolume) { uint HardwareSupp; _AudioEndPointVolume = realEndpointVolume; _Channels = new AudioEndpointVolumeChannels(_AudioEndPointVolume); _StepInformation = new AudioEndpointVolumeStepInformation(_AudioEndPointVolume); Marshal.ThrowExceptionForHR(_AudioEndPointVolume.QueryHardwareSupport(out HardwareSupp)); _HardwareSupport = (EEndpointHardwareSupport)HardwareSupp; _VolumeRange = new AudioEndPointVolumeVolumeRange(_AudioEndPointVolume); _CallBack = new AudioEndpointVolumeCallback(this); Marshal.ThrowExceptionForHR(_AudioEndPointVolume.RegisterControlChangeNotify( _CallBack)); }
internal AudioEndpointVolume(IAudioEndpointVolume realEndpointVolume) { uint HardwareSupp; _AudioEndPointVolume = realEndpointVolume; _Channels = new AudioEndpointVolumeChannels(_AudioEndPointVolume); _StepInformation = new AudioEndpointVolumeStepInformation(_AudioEndPointVolume); Marshal.ThrowExceptionForHR(_AudioEndPointVolume.QueryHardwareSupport(out HardwareSupp)); _HardwareSupport = (EEndpointHardwareSupport)HardwareSupp; _VolumeRange = new AudioEndPointVolumeVolumeRange(_AudioEndPointVolume); _CallBack = new AudioEndpointVolumeCallback(this); Marshal.ThrowExceptionForHR(_AudioEndPointVolume.RegisterControlChangeNotify(_CallBack)); }
public Speaker(MMDevice device, AudioEndPointVolumeVolumeRange volumeRange, float normalVolume) { Device = device; VolumeRange = volumeRange; NormalVolume = normalVolume; }