private static void ToggleMute(HashSet <int> appProcessIdCollection) { // Get all the processes that are an audio session var defaultAudioDevice = VolumeMixer.GetOutputDevice(); var sessionManager = VolumeMixer.GetAudioSessionManager2(defaultAudioDevice); var sessions = VolumeMixer.GetAudioSessionEnumerator(sessionManager); var audioControls = VolumeMixer.GetAudioContols(sessions); var audioProcessIdCollection = audioControls.Keys.ToHashSet(); // Get all the processes that are audio sessions of the focused application var commonProcessIdCollection = appProcessIdCollection.Intersect(audioProcessIdCollection); // Change the volume of all the audio processes of the focused application foreach (int processId in commonProcessIdCollection) { var volumeControl = audioControls[processId] as ISimpleAudioVolume; var currentMute = VolumeMixer.GetApplicationMute(volumeControl); VolumeMixer.SetApplicationMute(volumeControl, !currentMute ?? false); Marshal.ReleaseComObject(volumeControl); } Marshal.ReleaseComObject(defaultAudioDevice); Marshal.ReleaseComObject(sessionManager); Marshal.ReleaseComObject(sessions); }
public static void MuteProcess(int pId) { if (!IsMuted(pId)) { VolumeMixer.SetApplicationMute(pId, true); } }
public static void UnMuteProcess(int pId) { if (IsMuted(pId)) { VolumeMixer.SetApplicationMute(pId, false); } }
public MainWindow() { InitializeComponent(); VolumeMixer.SetApplicationMute("Idle", true); _dele = WinEventProc; SetWinEventHook(EventSystemForeground, EventSystemForeground, IntPtr.Zero, _dele, 0, 0, WineventOutofcontext); Apps.ItemsSource = _runningAudioApps; Muted.ItemsSource = MutedWindowStorage.Instance.Binding(); RefreshActiveApps(); }
/// <summary> /// Called whenever the active window changes /// </summary> private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { // Refresh List of Active Audio Apps RefreshActiveApps(); // Mute apps var focused = WindowUtil.GetActiveProcessName(); foreach (var app in MutedWindowStorage.Instance.Binding()) { VolumeMixer.SetApplicationMute(app, !app.Equals(focused)); } }
private async Task MuteCodIntermittently(Process process) { while (!StopMuting) { if (VolumeMixer.GetApplicationVolume(process.Id) == 100f) { if (codLaunchedTime == default) { codLaunchedTime = DateTime.Now; DelayedUnmute(); } } VolumeMixer.SetApplicationMute(process.Id, true); await Task.Delay(50); } codLaunchedTime = default; VolumeMixer.SetApplicationMute(process.Id, false); }
private async Task StartTableAsync(int mainThread) { logger.Info($"{RunMode.ToString()}: Starting table: {CurrentTable.Name}"); RunMode = Mode.SystemRunning; logger.Trace($"Setting Mode to {RunMode.ToString()}"); //Play Launch Music LMusicPlayer.Open(CurrentTable.LMusic); LMusicPlayer.Play(); var system = Data.FindSystem(CurrentTable); // get system to launch var proc = PinballFunctions.StartTable(system, CurrentTable); // launch system Stopwatch watchdog = new Stopwatch(); watchdog.Reset(); watchdog.Start(); //Wait for process to start (done this way for steam games) logger.Info($"Starting Game Process, Name: {system.Name}"); //proc.WaitForInputIdle(); await Task.Run(() => { while (Process.GetProcessesByName(system.Name).Length <= 0) { ; } }); var game = Process.GetProcessesByName(system.Name).First(); logger.Info($"Game Process Found, Handle: {game.Id}"); //keep hiding while window is starting await Task.Run(() => { do { //WindowControl.HideAllProcessWindows(system.Name, true); } while (WindowControl.FindProcessWindow(system.Name, system.WindowName) == IntPtr.Zero); //WindowControl.HideAllProcessWindows(system.Name); }); var windowHandle = WindowControl.FindProcessWindow(system.Name, system.WindowName); WindowControl.HideWindow(windowHandle, true); logger.Info($"Game Window Found, Process: {system.Name}, Name: {system.WindowName}, Handle: {windowHandle}"); //Try and Mute System watchdog.Restart(); logger.Info("Muting System"); await Task.Run(() => { while (VolumeMixer.GetApplicationMute(game.Id) != true) { //Console.WriteLine("Trying to Mute"); VolumeMixer.SetApplicationMute(game.Id, true); //WindowControl.SetFocus(ProgramName); if (watchdog.ElapsedMilliseconds > 10000) { logger.Warn($"Can't Mute System, Process ID: {game.Id}"); break; } } }); //Wait for Game to load await Task.Run(() => Task.Delay(system.WaitTime * 1000)); BGMusicPlayer.Pause(); //Unmute watchdog.Restart(); logger.Info("Unmuting System"); while (VolumeMixer.GetApplicationMute(game.Id) != false) { //Console.WriteLine("Trying to Unmute"); VolumeMixer.SetApplicationMute(game.Id, false); //WindowControl.SetFocus(ProgramName); if (watchdog.ElapsedMilliseconds > 10000) { logger.Warn($"Can't Unmute System, Process ID: {game.Id}"); break; } } //Show Game Window WindowControl.ShowWindow(windowHandle, true); //Focus GAME WindowControl.SetFocusForeground(windowHandle, true); //Hide Selected Windows logger.Trace("Setting Window Visibility"); BackglassWindow.Visibility = CurrentTable.ShowBackglass ? Visibility.Visible : Visibility.Hidden; DMDWindow.Visibility = CurrentTable.ShowDMD ? Visibility.Visible : Visibility.Hidden; PlayfieldVisibility = Visibility.Hidden; }