public AudioWorker() { _audioController = new CoreAudioController(); AudioDevice = _audioController.DefaultPlaybackDevice; _audioController.AudioDeviceChanged.Subscribe(this); }
static void Main(string[] args) { CoreAudioController controller = new CoreAudioController(); CoreAudioDevice device = controller.DefaultCaptureCommunicationsDevice; Console.WriteLine(device.FullName); while (true) { if (device.IsDefaultCommunicationsDevice) { if (device.SessionController.ActiveSessions().GetEnumerator().MoveNext()) { setColor(Color.red); } else { setColor(Color.green); } } Thread.Sleep(1000); if (!device.IsDefaultCommunicationsDevice) { device = controller.DefaultCaptureCommunicationsDevice; current = Color.na; Console.WriteLine(); Console.WriteLine(device.FullName); } } }
private IEnumerable <CoreAudioDevice> GetPlaybackDevices() { IEnumerable <CoreAudioDevice> devices = null; var reInitCoreAudioController = false; try { Log.Debug("Audio Switcher - getting all playback devices"); devices = _ac.GetDevices(DeviceType.Playback, DeviceState.Active); // Check for UNKNOWN devices and re-init CoreAudioControler if needed (AudioSwitcher API bug) foreach (var device in devices.Where(device => device.FullName.ToLower().Contains("unknown"))) { Log.Debug("Found unknown device during GetPlaybackDevices(), gonna re-init CoreAudioControler and update list"); Log.Debug("Device ID: " + device.Id); reInitCoreAudioController = true; } if (reInitCoreAudioController) { _ac = null; devices = null; _ac = new CoreAudioController(); devices = _ac.GetDevices(DeviceType.Playback, DeviceState.Active); } } catch (Exception ex) { Log.Error("Error occured during GetPlaybackDevices()"); Log.Error(ex.Message); } return(devices); }
public static void FindSoundDeviceByName(string sType, string sName) { CoreAudioController Controller = new CoreAudioController(); CoreAudioDevice device = null; if (sType == "input") { var devices = Controller.GetCaptureDevices(DeviceState.Active); foreach (var d in devices) { if (d.FullName == sName) { device = d; } } } else { var devices = Controller.GetDevices(DeviceState.Active); foreach (var d in devices) { if (d.FullName == sName) { device = d; } } } if (device != null) { ChangeStandardSoundDevice(device); } }
static async Task Main(string[] args) { var(config, hueConnector) = await SetupConfig(args); var controller = new CoreAudioController(); controller.AudioDeviceChanged.Subscribe(x => { if (x.ChangedType == DeviceChangedType.DefaultChanged && (_device == null || _device.Id != controller.DefaultCaptureCommunicationsDevice.Id)) { _device = controller.DefaultCaptureCommunicationsDevice; ObserveDevice(_device, hueConnector, config); } ; }); _device = controller.DefaultCaptureCommunicationsDevice; if (_device != null) { ObserveDevice(_device, hueConnector, config); } Console.ReadKey(true); }
public MainWindow() { InitializeComponent(); DataContext = this; Processes = new ObservableCollection <Process>(); AudioDevices = new ObservableCollection <IDevice>(); Controller = new CoreAudioController(autoLoad: false); // Signup to the loaded event, so we can start loading our audio devices once the application has displayed this.Loaded += MainWindow_Loaded; // Clear designer content and replace it with loading text, waiting for audio devices to initilize ApplicationGrid.IsEnabled = false; _loadedContent = this.Content; var loadingContent = new Label() { Content = "Loading Audio Devices...", HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, FontSize = 16, VerticalContentAlignment = VerticalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, }; this.Content = loadingContent; }
public static async Task Main() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.OSArchitecture != Architecture.X64) { Console.WriteLine("This program only supports Windows operating systems on the 64-bit architecture."); Environment.Exit(1); } using (CancellationTokenSource cTokenSource = new CancellationTokenSource()) { // Wait for CTRL+C so we can abort. Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => { cTokenSource.Cancel(); }; Console.WriteLine("[{0}] Press Ctrl+C to exit application.", DateTime.Now.ToString(Program.DATE_TIME_FORMAT_STRING)); // Create a new controller and get the default devices. CoreAudioController ctrl = new CoreAudioController(); CoreAudioDevice playbackDevice = ctrl.DefaultPlaybackDevice; CoreAudioDevice communicationsDevice = ctrl.DefaultCaptureCommunicationsDevice; // Observe the playback device. VolumeLockObserver playbackObs = new VolumeLockObserver(playbackDevice); playbackObs.Subscribe(playbackDevice.VolumeChanged); // Observe the capture device. VolumeLockObserver captureObs = new VolumeLockObserver(communicationsDevice); captureObs.Subscribe(communicationsDevice.VolumeChanged); // Wait indefinitely for CTRL+C. try { await Task.Delay(-1, cTokenSource.Token); } catch { Environment.Exit(0); } } }
// Get system volume public static void getVolume() { CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; output.volume = defaultPlaybackDevice.Volume; core.Exit("System volume received!", output); }
public static void SetVolumeOfDefault(int vol) { CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; //Console.WriteLine("Current Volume:" + defaultPlaybackDevice.Volume); defaultPlaybackDevice.Volume = vol; }
public VolumeControl() { InitializeComponent(); CoreAudioController coreAudioConteroller = new CoreAudioController(); App.CoreAudioDevice = coreAudioConteroller.GetDefaultDevice(AudioSwitcher.AudioApi.DeviceType.Playback, AudioSwitcher.AudioApi.Role.Multimedia); }
public MainWindow() { InitializeComponent(); ni.Icon = new System.Drawing.Icon("AmbientSound.ico"); ni.Visible = true; ni.Click += delegate(object sender, EventArgs args) { this.Show(); this.WindowState = WindowState.Normal; }; DeviceSelect.SelectedItem = null; DeviceSelect.Text = "Select a Device"; timer.Interval = TimeSpan.FromSeconds(5); timer.Tick += timer_Tick; populateDevices(); Directory.CreateDirectory(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NAudio")); CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; //onsole.Out.Write("\nCurrent Volume:" + defaultPlaybackDevice.Volume + "\n\n"); MinSlider.Value = (int)defaultPlaybackDevice.Volume; _playbackDevice = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, (VisioForge.Shared.NAudio.CoreAudioApi.Role)ERole.eMultimedia); //Console.Out.Write("\nMin Volume:" + (int)MinSlider.Value+ "\n\n"); //SetVolume((int) MinSlider.Value); }
public ResponseModel VolumeChange(double value) { try { CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; Debug.WriteLine("Current Volume:" + defaultPlaybackDevice.Volume); defaultPlaybackDevice.Volume = value; return new ResponseModel { Ok = true, Data = new {value = value}, Error = null }; } catch (Exception ex) { return new ResponseModel { Ok = false, Data = null, Error = ex.Message }; } }
private static void Init() { if (controller == null) { controller = new CoreAudioController(); } }
public IHttpContext SetVolume(IHttpContext context) { if (Authentication.Enabled) { HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity)context.User.Identity; if (!Authentication.VerifyAuthentication(identity)) { context.Response.SendResponse(JsonConvert.SerializeObject(Authentication.FailedAuthentication)); return(context); } } ResponseMessage Response = new ResponseMessage(); Response.Message = "Please input a correct numeric value."; Response.Successful = false; var volume = context.Request.QueryString["level"] ?? JsonConvert.SerializeObject(Response); CoreAudioController controller = new CoreAudioController(); CoreAudioDevice device = controller.DefaultPlaybackDevice; try { device.Volume = Convert.ToDouble(volume); Response.Message = $"Successfully changed volume level to {volume}."; Response.Successful = true; } catch (Exception e) { } context.Response.ContentEncoding = Encoding.Default; context.Response.SendResponse(JsonConvert.SerializeObject(Response)); return(context); }
private void slider1_ValueChanged(object sender, EventArgs e) { slider1.Text = slider1.Value.ToString(); CoreAudioDevice audio = new CoreAudioController().DefaultPlaybackDevice; audio.Volume = slider1.Value; }
public static List <string> GetAudioDevices(string sType) { List <string> arrReturn = new List <string> { }; CoreAudioController Controller = new CoreAudioController(); if (sType == "output") { var devices = Controller.GetPlaybackDevices(DeviceState.Active); foreach (var d in devices.OrderBy(x => x.Name)) { arrReturn.Add(d.FullName); } } else if (sType == "input") { var devices = Controller.GetCaptureDevices(DeviceState.Active); foreach (var d in devices.OrderBy(x => x.Name)) { arrReturn.Add(d.FullName); } } return(arrReturn); }
void Run() { try { NotifyIconContext.ToolTip("Starting controller"); using (var ctrl = new CoreAudioController()) { audio = ctrl; //NotifyIconContext.Info(1000, "Active", "Forcing all capture levels to " + Level + "%"); NotifyIconContext.Level(ConfigManager.Target); while (true) { UpdateLevel(reportFix: true); Thread.Sleep(1000); } } } catch (ThreadAbortException) { //Silent exit } catch (Exception ex) { NotifyIconContext.Error(60000, ex.GetType().Name, ex.Message); Thread.Sleep(60000); Application.Exit(); } }
public void LoadKnownDevices() { try { cbAvailableAudioDevices.Items.Clear(); cbAvailableAudioDevices.AutoCompleteCustomSource.Clear(); cbStartupPlaybackDevices.Items.Clear(); cbStartupPlaybackDevices.AutoCompleteCustomSource.Clear(); CoreAudioController _ac = new CoreAudioController(); IEnumerable <CoreAudioDevice> _knownDevices = _ac.GetDevices(DeviceType.Playback, DeviceState.Active); foreach (var device in _knownDevices) { cbAvailableAudioDevices.Items.Add(device.FullName); cbAvailableAudioDevices.AutoCompleteCustomSource.Add(device.FullName); cbStartupPlaybackDevices.Items.Add(device.FullName); cbStartupPlaybackDevices.AutoCompleteCustomSource.Add(device.FullName); } } catch (Exception ex) { MessageBox.Show("Error occured during GetPlaybackDevices()"); MessageBox.Show(ex.Message); } }
public VMonApplicationContext() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; icon = new NotifyIcon(); UpdateIconText("!", Color.Tomato, 10); icon.Visible = true; ContextMenu menu = new ContextMenu(); MenuItem exit = new MenuItem("Exit"); exit.Click += Exit_Click; menu.MenuItems.Add(exit); icon.ContextMenu = menu; Controller = new CoreAudioController(); var volObserver = new VolumeObserver(this); volObserver.Subscribe(Controller.DefaultPlaybackDevice.VolumeChanged); var muteObserver = new MuteObserver(this); muteObserver.Subscribe(Controller.DefaultPlaybackDevice.MuteChanged); var devObserver = new DeviceObserver(volObserver, muteObserver, this); devObserver.Subscribe(Controller.AudioDeviceChanged); }
static void Main(string[] args) { Console.WriteLine("Microphone un-muter by P Dring"); Console.WriteLine("This program will detect and unmute all microphones / webcams"); Console.WriteLine("Detecting microphones..."); CoreAudioController controller = new CoreAudioController(); foreach (CoreAudioDevice device in controller.GetCaptureDevices()) { Console.Write(" > Detected: " + device.FullName + ": "); if (device.IsMuted) { Console.Write("Muted - attempting to unmute"); device.Mute(false); if (device.IsMuted) { Console.Write(" failed :("); } else { Console.Write(" success :)"); } } else { Console.Write("Unmuted"); } Console.WriteLine(); } Console.WriteLine("Done - press enter to close this window"); Console.ReadLine(); }
public Form1() { InitializeComponent(); comboBox1.Items.AddRange(Enumerable.Range(0, 101).Select(e => new ListItem(e.ToString())).ToArray()); CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; switch (defaultPlaybackDevice.Volume) { case 4: comboBox1.SelectedIndex = 100; defaultPlaybackDevice.Volume = 100; label2.Text = "Current Volume:" + defaultPlaybackDevice.Volume; break; case 100: comboBox1.SelectedIndex = 4; defaultPlaybackDevice.Volume = 4; label2.Text = "Current Volume:" + defaultPlaybackDevice.Volume; break; default: comboBox1.SelectedIndex = 100; defaultPlaybackDevice.Volume = 100; label2.Text = "Current Volume:" + defaultPlaybackDevice.Volume; break; } }
private async Task <PcAudio> GetCurrentAudioStateAsync(CoreAudioController coreAudioController) { var audioState = new PcAudio { ApplicationVersion = ApplicationVersion, ProtocolVersion = ProtocolVersion }; var devices = await coreAudioController.GetPlaybackDevicesAsync(); foreach (var device in devices.Where(x => x.State == DeviceState.Active).ToList()) { audioState.DeviceIds.Add(device.Id.ToString(), device.FullName); } var defaultPlaybackDevice = coreAudioController.DefaultPlaybackDevice; audioState.DefaultDevice = new AudioDevice { Name = defaultPlaybackDevice.FullName, DeviceId = defaultPlaybackDevice.Id.ToString(), MasterVolume = defaultPlaybackDevice.Volume, MasterMuted = defaultPlaybackDevice.IsMuted }; return(audioState); }
//attackbutton sniper shot private void button2_Click(object sender, EventArgs e) { if (!enemyDead && pokemonChosen && enemyChosen == true) { Random random = new Random(); int randomNumber = random.Next(15, 40); CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; Debug.WriteLine("Current Volume:" + defaultPlaybackDevice.Volume); defaultPlaybackDevice.Volume = randomNumber; SoundPlayer audio = new SoundPlayer(MonsterBattle.Properties.Resources.yeet); audio.Play(); enemyPictureBox.Tag = enemyPictureBox.Image; enemyPictureBox.Image = Properties.Resources.gun; attackButton.Enabled = false; button1.Enabled = false; button2.Enabled = false; button3.Enabled = false; attackTimer.Start(); screenShakeTimer.Start(); gif_timer.Start(); } else { MessageBox.Show("You can not strike the enemy whilst he is already down. Or you haven't chosen a Feckermon/enemy yet."); } }
private void init() { m_updateListener = new UpdateListener(this); m_updateSubject .Synchronize() .Throttle(TimeSpan.FromMilliseconds(10)) .SubscribeOnDispatcher() .Subscribe(m_updateListener); m_sessionVolumeListener = new AudioSessionVolumeListener(this); m_sessionMuteListener = new AudioSessionMuteListener(this); m_coreAudioController = new CoreAudioController(); m_coreAudioController.DefaultPlaybackDevice.GetCapability <IAudioSessionController>().SessionCreated.Subscribe(new AudioSessionAddedListener(this)); m_coreAudioController.DefaultPlaybackDevice.GetCapability <IAudioSessionController>().SessionDisconnected.Subscribe(new AudioSessionRemovedListener(this)); m_coreAudioController.AudioDeviceChanged.Subscribe(new DeviceChangeListener(this)); var masterVolumeListener = new MasterVolumeListener(this); m_coreAudioController.DefaultPlaybackDevice.VolumeChanged.Throttle(TimeSpan.FromMilliseconds(10)).Subscribe(masterVolumeListener); m_coreAudioController.DefaultPlaybackDevice.MuteChanged.Throttle(TimeSpan.FromMilliseconds(10)).Subscribe(masterVolumeListener); new Thread(() => { updateState(null); Server = new Server(this); }).Start(); }
public void CoreAudioSessionController_Exists_As_Capability() { using (var controller = new CoreAudioController()) { var device = controller.DefaultPlaybackDevice; Assert.NotNull(device.GetCapability <IAudioSessionController>()); } }
private static void ajustaAudio() { CoreAudioDevice fone = new CoreAudioController().DefaultPlaybackDevice; CoreAudioDevice mic = new CoreAudioController().DefaultCaptureDevice; fone.Volume = 100; mic.Volume = 100; }
public YamahaAudioService() { InitializeComponent(); InitializeLoger(); _logger = LogManager.GetCurrentClassLogger(); _controller = new CoreAudioController(false); _requestTimer = new CustomTimer(25); }
private static float GetVolume() { using (var ctl = new CoreAudioController()) { var defaultPlaybackDevice = ctl.DefaultPlaybackDevice; return((float)(defaultPlaybackDevice.Volume / 100.0)); } }
// Set system volume public static void setVolume(string volume) { CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; //Debug.WriteLine("Current Volume:" + defaultPlaybackDevice.Volume); defaultPlaybackDevice.Volume = Int32.Parse(volume); core.Exit("System volume set to " + volume, output); }
private async Task UpdateStateAsync( PcAudio audioUpdate, CoreAudioController coreAudioController, CancellationToken stoppingToken) { if (audioUpdate?.DefaultDevice == null) { return; } var defaultPlaybackDevice = coreAudioController.DefaultPlaybackDevice; // Change default audio device. if (audioUpdate.DefaultDevice.DeviceId != defaultPlaybackDevice.Id.ToString()) { var deviceId = Guid.Parse(audioUpdate.DefaultDevice.DeviceId); var newDefaultAudioDevice = await coreAudioController.GetDeviceAsync(deviceId); await newDefaultAudioDevice.SetAsDefaultAsync(stoppingToken); await newDefaultAudioDevice.SetAsDefaultCommunicationsAsync(stoppingToken); return; } // Change muted and / or volume values. if (audioUpdate.DefaultDevice.MasterMuted.HasValue) { var muted = audioUpdate.DefaultDevice.MasterMuted.Value; if (muted != defaultPlaybackDevice.IsMuted) { await defaultPlaybackDevice.SetMuteAsync(muted, stoppingToken); } } if (audioUpdate.DefaultDevice.MasterVolume.HasValue) { const int increment = 2; var deviceAudioVolume = defaultPlaybackDevice.Volume; var clientAudioVolume = audioUpdate.DefaultDevice.MasterVolume.Value; var volume = deviceAudioVolume; if (clientAudioVolume < deviceAudioVolume) { volume -= increment; } else if (clientAudioVolume > deviceAudioVolume) { volume += increment; } // ReSharper disable once CompareOfFloatsByEqualityOperator if (volume != deviceAudioVolume) { await defaultPlaybackDevice.SetVolumeAsync(volume, stoppingToken); } } }
public MainWindow() { InitializeComponent(); Processes = new ObservableCollection<Process>(); AudioDevices = new ObservableCollection<IDevice>(); Controller = new CoreAudioController(); DataContext = this; }
public MicController() { this.controller = new CoreAudioController(); this.muteLock = new Object(); this.timer = new Timer(MUTE_DELAY); this.timer.AutoReset = false; this.timer.Elapsed += this.Timer_Elapsed; this.keyboardHook = new KeyboardHook(); this.keyboardHook.KeyDown += KeyboardHook_KeyDown; this.keyboardHook.KeyUp += KeyboardHook_KeyUp; this.mouseHook = new MouseHook(); this.mouseHook.ButtonDown += MouseHook_ButtonDown; this.mouseHook.ButtonUp += MouseHook_ButtonUp; this.Mute(true); }
private static int Main(string[] args) { if (args.Length > 2 || args.Length < 1) return PrintUsage(); //Process CLI Arguments for (var i = 0; i < args.Length - 1; i++) { switch (args[i]) { case "--debug": _isDebug = true; break; } } //Process file name string fName = args[args.Length - 1]; if (!fName.EndsWith(".js")) { Console.WriteLine("Invalid input file"); Console.WriteLine(); return PrintUsage(); } IAudioController controller; if (_isDebug) controller = new SandboxAudioController(new CoreAudioController()); else controller = new CoreAudioController(); using (var engine = new JsEngine()) { engine.AddCoreLibrary(); engine.AddAudioSwitcherLibrary(controller); //Enable to log to CLI //engine.SetGlobalValue("console", new ConsoleOutput(engine)); //engine.InternalEngine.SetGlobalValue("console", new FirebugConsole(engine.InternalEngine)); engine.SetOutput(new ConsoleScriptOutput()); try { Console.WriteLine("Executing {0}...", fName); var result = engine.Execute(new Scripting.FileScriptSource(fName)); if (!result.Success) throw result.ExecutionException; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } #if DEBUG Console.ReadKey(); #endif return 0; }