public static void Main(string[] args) { try { //Console.Clear(); Console.SetWindowSize(120, 40); AudioEndpointManager manager = new AudioEndpointManager(); if (args == null || args.Length == 0) { displayDevices(manager); return; } switch (args[0]) { case "/list": displayDevices(manager); break; case "/?": case "/help": displayHelpMessage(); break; case "/cro": Console.Write(string.Format("{0} {1} {2}", manager.DefaultOutputDevice.Id, manager.DefaultOutputDevice.Name, manager.DefaultOutputDevice.Bus)); break; case "/cri": Console.Write(string.Format("{0} {1} {2}", manager.DefaultInputDevice.Id, manager.DefaultInputDevice.Name, manager.DefaultInputDevice.Bus)); break; case "/so": if (args.Length == 2) manager.SetDefaultOutputDevice(args[1]); if (args.Length == 3) manager.SetDefaultOutputDevice(args[1], args[2]); if (args.Length > 4) manager.SetNextDefaultOutputDevice(args, 1); break; case "/si": if (args.Length == 2) manager.SetDefaultInputDevice(args[1]); if (args.Length == 3) manager.SetDefaultInputDevice(args[1], args[2]); if (args.Length > 4) manager.SetNextDefaultInputDevice(args, 1); break; default: break; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } /* AudioEndpoint audio = new AudioEndpoint(); try { audio.GetAudioInputDevices(); } catch (Exception e) { Console.WriteLine(e.ToString()); } try { audio.GetAudioOutputDevices(); } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.WriteLine("Output devices..."); foreach (KeyValuePair<String, String> device in audio.OutputDevicesPeriheral) Console.WriteLine(device.Key + " (" + device.Value + ") " + audio.OutputDevices[device.Key]); Console.WriteLine(); Console.WriteLine("Input devices..."); foreach (KeyValuePair<String, String> device in audio.InputDevicesPeriheral) Console.WriteLine(device.Key + " (" + device.Value + ") " + audio.InputDevices[device.Key]); Console.WriteLine(); Console.WriteLine("Default output device: " + audio.DefaultOutputDevice); Console.WriteLine("Default input device: " + audio.DefaultInputDevice); */ /* Console.WriteLine(); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); */ }
private static void displayDevices(AudioEndpointManager manager) { Console.WriteLine("Output Devices ({device name} on {bus name} {last used} |(default)| {device id})"); Console.WriteLine("--------------------------------------------------------------------------------"); foreach (AudioDevice device in manager.OutputDevices) Console.WriteLine(string.Format("{0} on {1} {4:yyyyMMdd HHmmss} {3}\t{2}", device.Name, device.Bus, device.Id, device.IsDefault ? "\t(default)" : "", device.LastDate)); Console.WriteLine(); Console.WriteLine("Input Devices ({device name} on {bus name} {last used} |(default)| {device id})"); Console.WriteLine("-------------------------------------------------------------------------------"); foreach (AudioDevice device in manager.InputDevices) Console.WriteLine(string.Format("{0} on {1} {4:yyyyMMdd HHmmss} {3}\t{2}", device.Name, device.Bus, device.Id, device.IsDefault ? "\t(default)" : "", device.LastDate)); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(string.Format("Default Output Device:\n{0} on {1}\t{2}", manager.DefaultOutputDevice.Name, manager.DefaultOutputDevice.Bus, manager.DefaultOutputDevice.Id)); Console.WriteLine(); Console.WriteLine(string.Format("Default Input Device:\n{0} on {1}\t{2}", manager.DefaultInputDevice.Name, manager.DefaultInputDevice.Bus, manager.DefaultInputDevice.Id)); Console.WriteLine(); Console.WriteLine(); }