private void LoadDevices()
        {
            _deviceEnumerator = _deviceEnumerator ?? new MMDeviceEnumerator();

            var defaultCapture = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console);
            var defaultRender  = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);

            _micDevices = new List <DeviceItem>();
            foreach (var device in _deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.All))
            {
                var item = new DeviceItem
                {
                    Device  = device,
                    Default = defaultCapture.ID == device.ID,
                    Index   = _micDevices.Count
                };
                _micDevices.Add(item);
            }

            micphone_selector.BeginUpdate();
            _micDevices.Sort((item1, item2) => item1.Default ? -1 : 1);
            micphone_selector.DataSource = _micDevices;
            micphone_selector.EndUpdate();

            _speakerDevices = new List <DeviceItem>();
            foreach (var device in _deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.All))
            {
                var item = new DeviceItem
                {
                    Device  = device,
                    Default = defaultRender.ID == device.ID,
                    Index   = _speakerDevices.Count
                };
                _speakerDevices.Add(item);
            }

            speaker_selector.BeginUpdate();
            _speakerDevices.Sort((item1, item2) => item1.Default ? -1 : 1);
            speaker_selector.DataSource = _speakerDevices;
            speaker_selector.EndUpdate();
        }
        private void speaker_selector_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool isChanged = false;

            if (_nowSpeakerDevice != null)
            {
                isChanged = true;
                _nowSpeakerDevice.Device.AudioEndpointVolume.OnVolumeNotification -= SpeakerAudioEndpointVolume_OnVolumeNotification;
            }
            _nowSpeakerDevice = _speakerDevices[speaker_selector.SelectedIndex];
            _nowSpeakerDevice.Device.AudioEndpointVolume.OnVolumeNotification += SpeakerAudioEndpointVolume_OnVolumeNotification;
            speaker_volume.Value = (int)(_nowSpeakerDevice.Device.AudioEndpointVolume.MasterVolumeLevelScalar * 100);
            Console.WriteLine("Speaker Changed:{0},Name:{1}", speaker_selector.SelectedIndex, _nowSpeakerDevice.FriendlyName);

            if (isChanged)
            {
                SetDefaultAudioEndPoint(_nowSpeakerDevice.Device.ID);
            }

            SwitcherDeviceTrack();
        }
        private void micphone_selector_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool isChanged = false;

            if (_nowMicDevice != null)
            {
                isChanged = true;
                _nowMicDevice.Device.AudioEndpointVolume.OnVolumeNotification -= AudioEndpointVolume_OnVolumeNotification;
            }
            _nowMicDevice = _micDevices[micphone_selector.SelectedIndex];
            _nowMicDevice.Device.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification;
            micphone_trackbar.Value = (int)(_nowMicDevice.Device.AudioEndpointVolume.MasterVolumeLevelScalar * 100);

            Console.WriteLine("Microphone Changed:{0},Name:{1}", micphone_selector.SelectedIndex, _nowMicDevice.FriendlyName);

            if (isChanged)
            {
                SetDefaultAudioEndPoint(_nowMicDevice.Device.ID);
            }

            SwitcherDeviceTrack();
        }
        private void LoadDevices()
        {
            _deviceEnumerator = _deviceEnumerator?? new MMDeviceEnumerator();

            var defaultCapture = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console);
            var defaultRender = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);

            _micDevices = new List<DeviceItem>();
            foreach (var device in _deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.All))
            {
                var item = new DeviceItem
                {
                    Device = device,
                    Default = defaultCapture.ID == device.ID,
                    Index = _micDevices.Count
                };
                _micDevices.Add(item);
            }

            micphone_selector.BeginUpdate();
            _micDevices.Sort((item1, item2) => item1.Default ? -1 : 1);
            micphone_selector.DataSource = _micDevices;
            micphone_selector.EndUpdate();

            _speakerDevices = new List<DeviceItem>();
            foreach (var device in _deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.All))
            {
                var item = new DeviceItem
                {
                    Device = device,
                    Default = defaultRender.ID == device.ID,
                    Index = _speakerDevices.Count
                };
                _speakerDevices.Add(item);
            }

            speaker_selector.BeginUpdate();
            _speakerDevices.Sort((item1, item2) => item1.Default ? -1 : 1);
            speaker_selector.DataSource = _speakerDevices;
            speaker_selector.EndUpdate();
        }
        private void speaker_selector_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool isChanged = false;
            if (_nowSpeakerDevice != null)
            {
                isChanged = true;
                _nowSpeakerDevice.Device.AudioEndpointVolume.OnVolumeNotification -= SpeakerAudioEndpointVolume_OnVolumeNotification;
            }
            _nowSpeakerDevice = _speakerDevices[speaker_selector.SelectedIndex];
            _nowSpeakerDevice.Device.AudioEndpointVolume.OnVolumeNotification += SpeakerAudioEndpointVolume_OnVolumeNotification;
            speaker_volume.Value = (int)(_nowSpeakerDevice.Device.AudioEndpointVolume.MasterVolumeLevelScalar * 100);
            Console.WriteLine("Speaker Changed:{0},Name:{1}", speaker_selector.SelectedIndex, _nowSpeakerDevice.FriendlyName);

            if (isChanged)
            {
                SetDefaultAudioEndPoint(_nowSpeakerDevice.Device.ID);
            }

            SwitcherDeviceTrack();
        }
        private void micphone_selector_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool isChanged = false;
            if (_nowMicDevice != null)
            {
                isChanged = true;
                _nowMicDevice.Device.AudioEndpointVolume.OnVolumeNotification -= AudioEndpointVolume_OnVolumeNotification;
            }
            _nowMicDevice = _micDevices[micphone_selector.SelectedIndex];
            _nowMicDevice.Device.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolume_OnVolumeNotification;
            micphone_trackbar.Value = (int)(_nowMicDevice.Device.AudioEndpointVolume.MasterVolumeLevelScalar * 100);

            Console.WriteLine("Microphone Changed:{0},Name:{1}",micphone_selector.SelectedIndex,_nowMicDevice.FriendlyName);

            if (isChanged)
            {
                SetDefaultAudioEndPoint(_nowMicDevice.Device.ID);
            }

            SwitcherDeviceTrack();
        }