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); } }
public VolumeLockObserver(CoreAudioDevice device) { this.device = device; this.lockValue = device.Volume; Console.WriteLine("[{0}] Locking [{1}] volume to {2}%.", DateTime.Now.ToString(Program.DATE_TIME_FORMAT_STRING), this.device.FullName, lockValue); }
static public IDictionary <string, object> getDeviceData(CoreAudioDevice device = null) { if (device == null) { device = mainDevice; } IDictionary <string, object> data = new Dictionary <string, object>(); data.Add("name", mainDevice.FullName); //Device Name + Interface data.Add("type", mainDevice.Name); //Name Only data.Add("interface", mainDevice.InterfaceName); //Interface Only data.Add("device", mainDevice.DeviceType); data.Add("icon", mainDevice.Icon); data.Add("iconPath", mainDevice.IconPath); data.Add("id", mainDevice.Id); data.Add("realID", mainDevice.RealId); data.Add("isMuted", mainDevice.IsMuted); data.Add("volume", mainDevice.Volume); //Master Volume data.Add("state", mainDevice.State); //Current State (Active/Disable) if (isJson) { System.Console.WriteLine(JsonConvert.SerializeObject(data, Formatting.Indented)); } else { foreach (KeyValuePair <string, object> kvp in data) { Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value); } } return(data); }
void GetAllSoundDevicesForContextMenu() { ContextMenuItems.Clear(); contextMenu.MenuItems.Clear(); Devices.Clear(); Devices = GetAllValidSoundDevices(); foreach (var device in Devices.ToList()) { MenuItem menuItemDevice = new MenuItem(device.InterfaceName, OnDeviceClick) { Tag = device }; ContextMenuItems.Add(menuItemDevice); contextMenu.MenuItems.AddRange(ContextMenuItems.ToArray()); } CoreAudioDevice defaultDevice = GetDefaultDevice(); MenuItem menuItemDefault = ContextMenuItems.Find(x => ((CoreAudioDevice)x.Tag).FullName == defaultDevice.FullName); if (menuItemDefault != null) { menuItemDefault.Checked = true; SetToolTip(defaultDevice.InterfaceName); } }
protected override void OnStart(string[] args) { SetServiceState(ServiceState.SERVICE_START_PENDING, 100000); _logger.Info("Service Started."); _controller.LoadDevices(false, false, false); _logger.Info("Successfully found {0} audio devices.", _controller.GetDevices().Count()); _selectedDevice = _controller.DefaultPlaybackDevice; if (_selectedDevice == null) { throw new InvalidOperationException("Error loading default playback device"); } _selectedDevice.ReloadAudioEndpointVolume(); _selectedDevice.VolumeChanged.Subscribe(this); _selectedDevice.MuteChanged.Subscribe(this); _logger.Info("Selected Default Audio Device ({0}) for volume tracking.", _selectedDevice.FullName); _requestTimer.OnTimer = _requestTimer_Elapsed; CommandStack.Add(new PowerChangeCommandItem(true)); CommandStack.Add(new LoadSceneCommandItem(3)); PerformCommandStack().Wait(); var volumeTask = _selectedDevice.GetVolumeAsync(); volumeTask.Wait(); CommandStack.Add(new VolumeChangeCommandItem(volumeTask.Result)); PerformCommandStack().Wait(); SetServiceState(ServiceState.SERVICE_RUNNING); }
private void Finale_Load(object sender, EventArgs e) { defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; defaultPlaybackDevice.Mute(false); defaultPlaybackDevice.Volume = 100; r = new Thread(ThreadWorker); r.Start(); // Full screen this.FormBorderStyle = FormBorderStyle.None; Screen screen = Screen.FromControl(this); // get screen for form this.Bounds = screen.Bounds; this.TopMost = true; this.BackColor = Color.Black; t = new System.Windows.Forms.Timer(); t.Tick += T_Tick; t.Interval = 10; t.Start(); t2 = new System.Windows.Forms.Timer(); t2.Tick += T2_Tick; t2.Interval = 14; t2.Start(); LuckyNumber.Text = "LUCKY NUMBER: " + LN.ToString(); LuckyNumber.BringToFront(); LuckyNumber.Height = this.Height; LuckyNumber.Width = this.Width; LuckyNumber.Visible = true; LuckyNumber.ForeColor = Color.Black; LuckyNumber.Update(); LuckyNumber.Refresh(); browser.Hide(); }
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 void OnDeviceChanged(CoreAudioDevice device, DeviceChangedType changedType) { LoggerHelper.Trace("Audio Device {0} - Change Type: {1}", device.Id, changedType); lock (devicesLock) { if (changedType == DeviceChangedType.DeviceRemoved || device.State != DeviceState.Active) { RemoveSubscriptions(device.Id); devices.Remove(device.Id); devicePeakValue.Remove(device.Id); } else { if (device.IsPlaybackDevice) { if (device.IsDefaultCommunicationsDevice) { commsPlayback = device; } if (device.IsDefaultDevice) { mediaPlayback = device; } } if (changedType == DeviceChangedType.DeviceAdded) { RemoveSubscriptions(device.Id); devicePeakSubs[device.Id] = device.PeakValueChanged.Subscribe(x => devicePeakValue[device.Id] = x.PeakValue); } devices[device.Id] = GetAudioDeviceInfo(device.Id); } } }
public static void TurnVolumeUp(ref CoreAudioDevice myDevice) { if (myDevice.Volume <= 98) { myDevice.Volume += 2; } }
public AudioWorker() { _audioController = new CoreAudioController(); AudioDevice = _audioController.DefaultPlaybackDevice; _audioController.AudioDeviceChanged.Subscribe(this); }
public static void TurnVolumeDown(ref CoreAudioDevice myDevice) { if (myDevice.Volume >= 2) { myDevice.Volume -= 2; } }
public MainForm() { InitializeComponent(); this.Text = String.Empty; this.FormBorderStyle = FormBorderStyle.None; this.ControlBox = false; this.DoubleBuffered = true; this._playBackDevice = new CoreAudioController().DefaultPlaybackDevice; this._allSong = new List <string>(); this.musicProcessBar.Enabled = false; setup(); this.DoubleBuffered = true; this._mediaForm = new MediaForm(this, this._playedList); this._pictureForm = new PictureForm(this); this._videoForm = new VideoForm(); this._playListForm = new PlayListForm(this); this._nowPlayingForm = new NowPlayingForm(); this._mediaForm.UserChoiceChanged += playButton_Click; this._nowPlayingForm.FormBorderStyle = FormBorderStyle.None; this._nowPlayingForm.TopLevel = false; this.Dock = DockStyle.Left; this.mainBotPanel.Controls.Add(this._nowPlayingForm); _nowPlayingForm.BringToFront(); this._nowPlayingForm.Visible = false; this.backwardButton.Visible = false; }
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); }
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); } } }
public static void GetMicAsync() { if (device == null) { var devices = audioController.GetCaptureDevices(DeviceState.Active); device = devices.FirstOrDefault(x => x.IsDefaultDevice); } }
public MainForm() { InitializeComponent(); soundFileDialog.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); challengeFileDialog.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); wmPlayer = new WMPLib.WindowsMediaPlayer(); defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; }
public CoreAudioDevice GetCoreAudioDevice(string id) { Guid guid = new Guid(id); CoreAudioDevice result = coreAudioDeviceList.Find(a => a.Id.Equals(guid)); return(result); }
// Volume control constructor public VolumeControl() { // Instantiate the timer SetMaxVolumeTimer = new System.Timers.Timer { Interval = Constants.VoluemeTime, Enabled = true }; this.defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; }
public AudioDevice(string guid) { this.device = new CoreAudioController().GetDevice(Guid.Parse(guid)); this.muteObserver = new MuteObserver(this); this.muteObserver.Subscribe(this.device.MuteChanged); this.lastAction = DateTime.Now; }
private void InitializeAudioDevice() { m_audioDevice = new CoreAudioController().DefaultPlaybackDevice; // let's adjust the volume bar double width = m_audioDevice.Volume / MaximumVolume; VolumeRect.Width = width * m_volumeRectSize.Width; }
private void ChangeDevice() { int c; CoreAudioDevice CAD; string[] fav = GetDeviceList(); ChargeDevicesList(); if (lstDevices.CheckedItems.Count == 0) { return; } if (lstDevices.CheckedItems.Count == 1) { CAD = (CoreAudioDevice)lstDevices.CheckedItems[0]; if (!CAD.IsDefaultDevice) { if (fav.Contains(CAD.Id.ToString())) { if (Controller.SetDefaultDevice(CAD)) { DefaultAudioDevice = CAD; txtActualDevice.Text = DefaultAudioDevice.FullName; ShowNotification("Default device now is: " + DefaultAudioDevice.FullName); } } } return; } for (c = index; c < lstDevices.CheckedItems.Count; c++) { CAD = (CoreAudioDevice)lstDevices.CheckedItems[c]; if (!CAD.IsDefaultDevice) { if (fav.Contains(CAD.Id.ToString())) { if (Controller.SetDefaultDevice(CAD)) { DefaultAudioDevice = CAD; txtActualDevice.Text = DefaultAudioDevice.FullName; index = c; ShowNotification("Default device now is: " + DefaultAudioDevice.FullName); return; } } } if (c + 1 == lstDevices.CheckedItems.Count) { c = -1; } } }
private void Start() { var controller = new CoreAudioController(true, false, false, false); CoreAudioDevice defaultPlaybackDevice = controller.DefaultPlaybackDevice; defaultPlaybackDevice.ReloadAudioEndpointVolume(); defaultPlaybackDevice.VolumeChanged.Subscribe(this); Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); }
public void OnNext(DefaultDeviceChangedArgs value) { var newDefaultDevice = (CoreAudioDevice)value.Device; if (defaultPlaybackDevice.Id != newDefaultDevice.Id) { defaultPlaybackDevice = (CoreAudioDevice)value.Device; MessageRecieved?.Invoke(this, new CommandReceived(CommandReceived.CommandTypes.Other, "Default audio device changed")); } }
private async void SetDefaultButton_Click(object sender, EventArgs e) { if (DevicesListView.SelectedItems.Count == 1) { CoreAudioDevice newPlaybackDevice = (CoreAudioDevice)DevicesListView.SelectedItems[0].Tag; DevicesListView.SelectedItems.Clear(); await newPlaybackDevice.SetAsDefaultAsync(); } MakeDefaultButton.Enabled = false; }
public static void ChangeStandardSoundDevice(CoreAudioDevice device) { CoreAudioController Controller = new CoreAudioController(); //Controller.SetDefaultDevice(device); //Controller.SetDefaultCommunicationsDevice(device); //Controller.DefaultPlaybackDevice.SetAsDefault(); device.SetAsDefault(); device.SetAsDefaultCommunications(); }
public MainWindow() { InitializeComponent(); HotkeysManager.SetupSystemHook(); GlobalHotkey hotkey1 = new GlobalHotkey(ModifierKeys.Alt, Key.N, Hotkey1); GlobalHotkey hotkey2 = new GlobalHotkey(ModifierKeys.Alt, Key.M, Hotkey2); HotkeysManager.AddHotkey(hotkey1); HotkeysManager.AddHotkey(hotkey2); #region send application to tray System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); ni.Icon = new System.Drawing.Icon("image.ico"); ni.Visible = true; ni.Click += delegate(object sender, EventArgs e) { this.Show(); this.WindowState = System.Windows.WindowState.Normal; }; ni.DoubleClick += delegate(object sender, EventArgs e) { this.WindowState = System.Windows.WindowState.Normal; close = true; this.Close(); }; #endregion audioController = new CoreAudioController(); defaultOutput = audioController.DefaultPlaybackDevice; var OutputDevices = audioController.GetPlaybackDevices(DeviceState.Active); foreach (var device in OutputDevices) { dropDownMenu.Items.Add(device.FullName); dropDownMenu2.Items.Add(device.FullName); } data = SaveLoadManager.Load(); if (data != null) { dropDownMenu.Text = data.device1Name; dropDownMenu2.Text = data.device2Name; } AddHotKeys(); }
private void PollVolume_Tick(object sender, EventArgs e) { idleTimer += muted ? 4 : 1; if ((lastVolume != playbackDevice.Volume) || (muted != playbackDevice.IsMuted)) { lastVolume = playbackDevice.Volume; muted = playbackDevice.IsMuted; idleTimer = 0; visibility = 1; volFG.Location = new Point(0, 80 - (int)(playbackDevice.Volume / 100 * 80)); VolTxt.Text = $"{playbackDevice.Volume}"; if (muted) { byte dColor = (byte)((BarColor.R + BarColor.G + BarColor.B) / 9); volFG.BackColor = Color.FromArgb(dColor, dColor, dColor); VolTxt.Text = $"({VolTxt.Text})"; VolTxt.ForeColor = Color.DarkSlateGray; volDot.BackColor = Color.DarkSlateGray; } else { volFG.BackColor = BarColor; VolTxt.ForeColor = Color.White; volDot.BackColor = Color.Silver; } Opacity = 1; } if (idleTimer > 40) { visibility -= .1d; if (visibility < 0) { visibility = 0; playbackDevice = controller.DefaultPlaybackDevice; } Opacity = visibility; } if ((ClientSize.Width != 32) || (ClientSize.Height != 128)) { ClientSize = new Size(32, 128); MaximizeBox = false; MaximumSize = new Size(32, 128); MinimizeBox = false; MinimumSize = new Size(32, 128); WindowState = FormWindowState.Normal; } if ((Location.X != 32) || (Location.Y != 32)) { Location = new Point(32, 32); WindowState = FormWindowState.Normal; } TopMost = false; TopMost = true; }
public bool Perform(KeybindDevice device, Keys key, KeyState state, KeyState lastState, string guid, params object[] args) { AudioDeviceAction action = AudioDeviceAction.ToggleMute; if (args.Length > 0 && args[0] is string str) { if (str.Length == ToggleMute.Length && str.Equals(ToggleMute)) { action = AudioDeviceAction.ToggleMute; } else if (str.Length == Mute.Length && str.Equals(Mute)) { action = AudioDeviceAction.Mute; } else if (str.Length == Unmute.Length && str.Equals(Unmute)) { action = AudioDeviceAction.Unmute; } else if (str.Length == SetVolume.Length && str.Equals(SetVolume) || str.Length == Volume.Length && str.Equals(Volume)) { action = AudioDeviceAction.SetVolume; } else { return(false); } } CoreAudioDevice mic = Audio.Controller.DefaultCaptureDevice; Audio.Speech.SpeakAsyncCancelAll(); if (action == AudioDeviceAction.ToggleMute || action == AudioDeviceAction.Mute || action == AudioDeviceAction.Unmute) { bool mute = action == AudioDeviceAction.ToggleMute ? !mic.IsMuted : action == AudioDeviceAction.Mute ? true : false; mic.Mute(mute); Audio.Speech.SpeakAsync($"Microphone {(mute ? "muted" : "activated")}"); //Audio.Speech.SpeakAsync(mute ? "Muted" : "Activated"); } else if (action == AudioDeviceAction.SetVolume) { if (args.Length < 2 || !(args[1] is long volume) || volume < 0 || volume > 100) { return(false); } mic.Volume = volume; Audio.Speech.SpeakAsync($"Microphone volume set to {volume}"); } return(true); }
public void Stop() { if (muteDevice == null) { return; } timer?.Dispose(); muteDevice.Mute(initiallyMuted); muteDevice = null; }
private VolumeService() { _setPreferences(); _defaultDevice = new CoreAudioController().DefaultPlaybackDevice; _timerVolUp = new Timer(_timerInterval); _timerVolDown = new Timer(_timerInterval); _timerVolUp.Elapsed += _timerVolUp_Elapsed; _timerVolDown.Elapsed += _timerVolDown_Elapsed; }