public override void Run(AudioDeviceViewModel argument) { if (argument.Device.IsActive) { _deviceManager.SetDefaultAudioDevice(argument.Device); } }
private void SwitchDevice() { var manager = new AudioDeviceManager(); var devices = manager.GetAudioDevices(AudioDeviceKind.Playback, AudioDeviceState.Active); var current = manager.GetDefaultAudioDevice(AudioDeviceKind.Playback, AudioDeviceRole.Multimedia) .ToString() .ToUpper() .Replace(" ", ""); var headphones = Args["headphones"] .ToUpper() .Replace(" ", ""); var speakers = Args["speakers"] .ToUpper() .Replace(" ", ""); AudioDevice device = null; if (current == headphones) { device = devices.FirstOrDefault(d => d.ToString().ToUpper().Replace(" ", "") == speakers); } else { device = devices.FirstOrDefault(d => d.ToString().ToUpper().Replace(" ", "") == headphones); } if (device != null) { manager.SetDefaultAudioDevice(device, AudioDeviceRole.Multimedia); } }
private void OnDeviceStateChanged(object sender, AudioDeviceStateEventArgs e) { if (!Settings.Default.AutoSwitchToPluggedInDevice) { return; } // NOTE: The audio stack does a pretty good job of switching inputs when an audio device // is unplugged. For example, if you plug your headphones in and we then set that to the // default device, then you unplug them, Windows will switch back to the last set default // audio device. This means that we don't need any smarts here to remember previous // devices. if (e.NewState == AudioDeviceState.Active) { _manager.SetDefaultAudioDevice(e.Device); } }
public override void Run() { _manager.SetDefaultAudioDevice(_device, _role); }
public override void Run() { _deviceManager.SetDefaultAudioDevice(_device); }