private CoreAudioDevice GetActiveDevice() { switch (targetMicrophoneState) { case TargetMicrophoneState.Default: return(controller.DefaultCaptureDevice); case TargetMicrophoneState.DefaultCommunications: return(controller.DefaultCaptureCommunicationsDevice); case TargetMicrophoneState.Specific: return(controller.GetDevice(selectedDeviceGuid.Value)); } return(null); }
static void Main(string[] args) { var audioControllerc = new CoreAudioController(); if ((args.FirstOrDefault() ?? "") == "save") { if (args.Length < 2 || args[1] != "TV" || args[1] != "Normal") { SaveMultimediaConfig(audioControllerc, args[1]); } return; } var configToUse = "Normal"; if (!string.IsNullOrWhiteSpace(args.FirstOrDefault())) { configToUse = args[0]; } var tvAuth = ConfigurationManager.AppSettings["TvAuth"]; var tvIpAddress = ConfigurationManager.AppSettings["TvIpAddress"]; var tvInput = ConfigurationManager.AppSettings["TvInput"]; var vizioController = new VizioController(tvAuth, tvIpAddress); if (configToUse == "TV") { vizioController.TurnOnTv(); vizioController.SetInput(tvInput); } else { vizioController.TurnOffTv(); } var configJson = File.ReadAllText($@"C:\MonitorConfigs\{configToUse}.txt"); var configToSet = JsonConvert.DeserializeObject <MultimediaSetup>(configJson); MonitorSwitcher.SetConfig(configToSet.MonitorConfig); audioControllerc.GetDevice(configToSet.DefaultAudioId).SetAsDefault(); }
static void ProcessTimer(object source, ElapsedEventArgs e) { Guid deviceId = (Guid)Properties.Settings.Default["DeviceId"]; int found = FindWindow("CUIEngineWin32", "Steam"); if (found != 0 && !(audioSwitched)) { Console.WriteLine("Big Picture!"); audioSwitched = true; CoreAudioDevice newDevice = audio.GetDevice(deviceId); audio.SetDefaultDevice(newDevice); } else if (found == 0 && audioSwitched) { audioSwitched = false; audio.SetDefaultDevice(startDevice); } }
public override void OnButtonUp(DeckDevice deckDevice) { var audioController = new CoreAudioController(); var device = Task.FromResult(audioController.GetDevice(DeviceId, DeviceState.All)).Result; // var device = ControllerHelper.getDeviceByGuid(DeviceId); switch (Key) { case MediaInputDevice.Mute: if (device != null) { var result = Task.FromResult(device.ToggleMuteAsync().Result); IDeckHelper.setVariable(result.Result, atual_item, deckDevice); } break; case MediaInputDevice.Default: if (device != null) { Task.FromResult(device.SetAsDefaultAsync()); } break; case MediaInputDevice.VolumeUp: if (device != null) { volume = Math.Round(VolumeStepper + device.Volume); Task.FromResult(device.SetVolumeAsync(volume)); } break; case MediaInputDevice.VolumeDown: if (device != null) { volume = Math.Round(device.Volume - VolumeStepper); Task.FromResult(device.SetVolumeAsync(volume)); } break; } }
// ReSharper disable once UnusedMethodReturnValue.Local private bool updateState(PcAudio audioUpdate) { //Console.WriteLine("update"); lock (m_lock) { var audioState = new PcAudio { protocolVersion = PROTOCOL_VERSION, applicationVersion = APPLICATION_VERSION }; cleanUpSessionKeepers(); var defaultDevice = m_coreAudioController.GetDefaultDevice(DeviceType.Playback, Role.Multimedia); if (defaultDevice == null) { return(true); } var defaultDeviceId = defaultDevice.Id.ToString(); // Add all available audio devices to our list of device IDs var devices = m_coreAudioController.GetPlaybackDevices(); foreach (var device in devices) { if (device.State == DeviceState.Active) { audioState.deviceIds.Add(device.Id.ToString(), device.FullName); } } // Master device updates if (audioUpdate?.defaultDevice != null) { if (!audioUpdate.defaultDevice.deviceId.Equals(defaultDeviceId)) { var deviceId = Guid.Parse(audioUpdate.defaultDevice.deviceId); var newDefaultAudioDevice = m_coreAudioController.GetDevice(deviceId); if (newDefaultAudioDevice != null) { //Console.WriteLine("Updated default audio device: " + audioUpdate.defaultDevice.deviceId); newDefaultAudioDevice.SetAsDefaultAsync().Wait(); newDefaultAudioDevice.SetAsDefaultCommunicationsAsync().Wait(); return(false); } //else //{ //Console.WriteLine("Failed to update default audio device. Could not find device for ID: " + audioUpdate.defaultDevice.deviceId); //} } else { if (audioUpdate.defaultDevice.masterMuted != null || audioUpdate.defaultDevice.masterVolume != null) { if (audioUpdate.defaultDevice.masterMuted != null) { var muted = audioUpdate.defaultDevice.masterMuted ?? m_coreAudioController.DefaultPlaybackDevice.IsMuted; //Console.WriteLine("Updating master mute: " + muted); m_coreAudioController.DefaultPlaybackDevice.SetMuteAsync(muted).Wait(); } // ReSharper disable once InvertIf if (audioUpdate.defaultDevice.masterVolume != null) { const int increment = 2; var deviceAudio = m_coreAudioController.DefaultPlaybackDevice.Volume; var clientAudio = audioUpdate.defaultDevice.masterVolume; var volume = deviceAudio; if (clientAudio < deviceAudio) { volume -= increment; } else if (clientAudio > deviceAudio) { volume += increment; } //var volume = audioUpdate.defaultDevice.masterVolume ?? (float)m_coreAudioController.DefaultPlaybackDevice.Volume; //Console.WriteLine("Updating master volume: " + volume); m_coreAudioController.DefaultPlaybackDevice.SetVolumeAsync(volume).Wait(); } return(false); } } } // Create our default audio device and populate it's volume and mute status var audioDevice = new AudioDevice(defaultDevice.FullName, defaultDeviceId); audioState.defaultDevice = audioDevice; var defaultPlaybackDevice = m_coreAudioController.DefaultPlaybackDevice; audioDevice.masterVolume = (float)defaultPlaybackDevice.Volume; audioDevice.masterMuted = defaultPlaybackDevice.IsMuted; // Go through all audio sessions foreach (var session in defaultDevice.GetCapability <IAudioSessionController>()) { if (session.IsSystemSession) { continue; } // If we haven't seen this before, create our book keeper var sessionId = session.Id; if (!m_sessions.ContainsKey(sessionId)) { //Console.WriteLine("Found new audio session"); var sessionKeeper = new AudioSessionKeeper(session, m_sessionVolumeListener, m_sessionMuteListener); m_sessions.Add(session.Id, sessionKeeper); } try { // Audio session update if (audioUpdate?.defaultDevice?.deviceId != null) { if (audioUpdate.defaultDevice.deviceId.Equals(defaultDeviceId)) { if (audioUpdate.defaultDevice.sessions != null && audioUpdate.defaultDevice.sessions.Count > 0) { foreach (var sessionUpdate in audioUpdate.defaultDevice.sessions. Where(sessionUpdate => sessionUpdate.id.Equals(session.Id))) { //Console.WriteLine("Adjusting volume: " + sessionUpdate.name + " - " + sessionUpdate.volume); //Console.WriteLine("Adjusting mute: " + sessionUpdate.muted + " - " + sessionUpdate.muted); session.SetVolumeAsync(sessionUpdate.volume).Wait(); session.SetMuteAsync(sessionUpdate.muted).Wait(); break; } } } } var sessionName = session.DisplayName; if (sessionName == null || sessionName.Trim() == "") { using var process = Process.GetProcessById(session.ProcessId); } var audioSession = new AudioSession(sessionName, session.Id, (float)session.Volume, session.IsMuted); audioDevice.sessions.Add(audioSession); } catch (Exception) { //Console.WriteLine(e.Message); //Console.WriteLine(e.StackTrace); //Console.WriteLine("Process in audio session no longer alive"); var sessionKeeper = m_sessions[session.Id]; m_sessions.Remove(session.Id); sessionKeeper.Dispose(); } } m_audioState = audioState; } return(true); }
public IDevice getSelectedDevice() { return(selectedDeviceId == "" ? AudioController.DefaultCaptureDevice : AudioController.GetDevice(new Guid(selectedDeviceId), DeviceState.Active)); }
public TrayApplication() { coreAudioController = new CoreAudioController(); manager = new HotKeyManager(); if (File.Exists("save.mm")) { using (var r = new BinaryReader(File.OpenRead("save.mm"))) { if (r.BaseStream.Length >= 40) { var g = new Guid(r.ReadString()); CoreAudioDevice mic = coreAudioController.GetDevice(g); if (mic != null && mic.State == DeviceState.Active) { microphone = mic; } else { microphone = coreAudioController.GetDefaultDevice(DeviceType.Capture, Role.Communications); } beepEnabled = r.ReadBoolean(); Register((ModifierKeys)r.ReadInt32(), (Key)r.ReadInt32(), true); if (r.BaseStream.Position != r.BaseStream.Length) { onBeep.Freq = r.ReadInt32(); onBeep.Duration = r.ReadInt32(); offBeep.Freq = r.ReadInt32(); offBeep.Duration = r.ReadInt32(); } else { onBeep.Freq = 750; onBeep.Duration = 200; offBeep.Freq = 300; offBeep.Duration = 200; } if (r.BaseStream.Position != r.BaseStream.Length) { notificationBallForm = new NotificationBallForm { Enabled = r.ReadBoolean() }; notificationBallForm.DraggingEnd += (asd, esd) => Save(); notificationBallForm.Show(); notificationBallForm.Visible = notificationBallForm.Enabled; notificationBallForm.Location = new Point(r.ReadInt32(), r.ReadInt32()); } else { notificationBallForm = new NotificationBallForm { Enabled = false }; notificationBallForm.Show(); notificationBallForm.Visible = false; } } } } else { microphone = coreAudioController.GetDefaultDevice(DeviceType.Capture, Role.Communications); beepEnabled = false; onBeep.Freq = 750; onBeep.Duration = 200; offBeep.Freq = 300; offBeep.Duration = 200; notificationBallForm = new NotificationBallForm { Enabled = false }; notificationBallForm.Show(); notificationBallForm.Visible = false; Register(ModifierKeys.None, Key.None); } trayMenu = new ContextMenuStrip(); trayMenu.Items.Add(new ToolStripMenuItem("Toogle Mute", default, ToggleMute));