Beispiel #1
0
        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);
        }
        protected override void ProcessRecord()
        {
            MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
            MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);

            for (int i = 0; i < devices.Count; i++)
            {
                WriteObject(new AudioDevice(i, devices[i]));
            }
        }
        public static Dictionary<string, string> GetAudioDevices()
        {
            Dictionary<string, string> audioDevices = new Dictionary<string, string>();

            audioDevices["Default Device"] = string.Empty;

            MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
            MMDeviceCollection dc = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);
            for (int i = 0; i < dc.Count; i++)
            {
                audioDevices[dc[i].FriendlyName] = dc[i].ID;
            }

            return audioDevices;
        }
        protected override void ProcessRecord()
        {
            MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
            MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);
            MMDevice DefaultDevice = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);

            for (int i = 0; i < devices.Count; i++)
            {
                if (devices[i].ID == DefaultDevice.ID)
                {
                    WriteObject(new AudioDevice(i, devices[i]));
                    return;
                }
            }
        }
Beispiel #5
0
        private void GetAudioDevices(ComboBox box, string audDevice)
        {
            box.Items.Clear();
            box.DisplayMember = "Text";
            box.ValueMember = "Value";
            box.Items.Add(new AudioDevice() { Text = "Default Device", Value = string.Empty });
            box.SelectedIndex = 0;

            MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
            MMDeviceCollection dc = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);
            for (int i = 0; i < dc.Count; i++)
            {
                box.Items.Add(new AudioDevice() { Text = dc[i].FriendlyName, Value = dc[i].ID });
                if(audDevice == dc[i].ID)
                    box.SelectedIndex = i+1;
            }
        }
        protected override void ProcessRecord()
        {
            MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
            MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);
            MMDevice defaultDevice = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);

            WriteObject(string.Format("{0}%", defaultDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100));
        }
        protected override void ProcessRecord()
        {
            MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
            MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);
            MMDevice defaultDevice = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);

            ProgressRecord pr = new ProgressRecord(0, defaultDevice.FriendlyName, "Peak Value");
            pr.PercentComplete = 0;

            if (streamValue)
                WriteObject(0);
            else
                WriteProgress(pr);

            do{
                pr.PercentComplete = System.Convert.ToInt32( defaultDevice.AudioMeterInformation.MasterPeakValue * 100);

                if (streamValue)
                    WriteObject(System.Convert.ToInt32(defaultDevice.AudioMeterInformation.MasterPeakValue * 100));
                else
                    WriteProgress(pr);

                Thread.Sleep(100);

            } while (!Stopping);
        }
        protected override void ProcessRecord()
        {
            MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
            MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);
            MMDevice defaultDevice = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);

            defaultDevice.AudioEndpointVolume.MasterVolumeLevelScalar = volume / 100.0f;
        }
        protected override void ProcessRecord()
        {
            MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
            MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);
            MMDevice defaultDevice = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);

            defaultDevice.AudioEndpointVolume.Mute = NoToggle || !defaultDevice.AudioEndpointVolume.Mute;
        }
        protected override void ProcessRecord()
        {
            MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
            MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);

            PolicyConfigClient client = new PolicyConfigClient();

            if (!string.IsNullOrEmpty(name))
            {
                for (int i = 0; i < devices.Count; i++)
                {
                    if (string.Compare(devices[i].FriendlyName, name, StringComparison.CurrentCultureIgnoreCase) == 0)
                    {
                        index = i;
                        break;
                    }
                }
            }

            if (inputObject != null)
            {
                for (int i = 0; i < devices.Count; i++)
                {
                    if (devices[i].ID == inputObject.Device.ID)
                    {
                        index = i;
                        break;
                    }
                }
            }

            client.SetDefaultEndpoint(devices[index].ID, ERole.eCommunications);
            client.SetDefaultEndpoint(devices[index].ID, ERole.eMultimedia);

            WriteObject(new AudioDevice(index, devices[index]));
        }
        private void initAudioDeviceControl()
        {
            MMDeviceEnumerator devEnum = new MMDeviceEnumerator();

            if (devEnum.EnumerateAudioEndPoints(EDataFlow.eCapture, EDeviceState.DEVICE_STATE_ACTIVE).Count > 0)
            {
                // Set capture device to default.
                captureDevice = devEnum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia);
                CaptureDeviceInterface = getDeviceInterfaceFriendlyName(captureDevice);
                CaptureDeviceLine = captureDevice.FriendlyName;
            }

            if (devEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE).Count > 0)
            {
                // Set render device to default.
                renderDevice = devEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
                RenderDeviceInterface = getDeviceInterfaceFriendlyName(renderDevice);
                RenderDeviceLine = renderDevice.FriendlyName;
            }
        }
 /// <summary>
 /// Retrieve the collection of render devices.
 /// </summary>
 /// <returns></returns>
 private MMDeviceCollection getRenderDeviceCollection()
 {
     MMDeviceEnumerator devEnum = new MMDeviceEnumerator();
     return devEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE);
 }
        public KeyValuePair<string, string> GetWindowsSelectedCaptureDeviceInfo()
        {
            KeyValuePair<string, string> kvp;

            // Retrieve the device selected by default in windows sound configuration
            MMDeviceEnumerator devEnum = new MMDeviceEnumerator();

            if(devEnum.EnumerateAudioEndPoints(EDataFlow.eCapture, EDeviceState.DEVICE_STATE_ACTIVE).Count > 0){

                MMDevice captureDevice = devEnum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia);

                // Get the name of the default's device interface
                string deviceInterface = getDeviceInterfaceFriendlyName(captureDevice);

                // Create the key value pair that will contain the device interface name as a key and the line name as a value.
                kvp = new KeyValuePair<string, string>(deviceInterface, captureDevice.FriendlyName);

            }else{
                kvp = new KeyValuePair<string, string>("", "");
            }

               return kvp;
        }