Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I made a program that plays relaxing MP3 music for one to fall asleep and in the end it lowers the Windows' systems sound level gradually to 0, how to make it while it's playing the MP3 file, all other applications in Windows including Windows itself not play sound for example no notifications sounds or Nexus clock speaking the time every round hour for example for the user to sleep with the relaxing music and no distracting sounds for him while he's falling asleep.

What I have tried:

I want something like:
foreach(Process p in lstWindowsProcesses)
{
if(p!=thisProcesss) p.Mute();
}


And when the program is not open anymore:
foreach(Process p in lstWindowsProcesses)
{
p.Unmute();
}


Or maybe store their previous state in volume and restore it when the program exits or there's a power outage and the computer is turned on again.
Posted
Updated 22-Dec-21 2:11am
Comments
[no name] 22-Dec-21 9:39am    
I'd call it a security issue if it works. My field work app gives verbal warnings.
FierceLion 22-Dec-21 9:40am    
Yes, when the user presses: "Start relaxing music for sleeping" he would be warned and the program would explain that all other processes would be muted so no notification wakes him up for example...
j snooze 23-Dec-21 17:22pm    
you may want to take a look at this

https://stackoverflow.com/questions/42055633/can%C2%B4t-mute-windows-media-player-by-process-id
FierceLion 25-Dec-21 9:42am    
Thanks, it linked then to here:

https://stackoverflow.com/questions/20938934/controlling-applications-volume-by-process-id

And in the main answer there's a code to include in my app with this in it to make it work:

// dump all audio sessions
foreach (AudioSession session in AudioUtilities.GetAllSessions())
{
if (session.Process != null)
{
// only the one associated with a defined process
Console.WriteLine(session.Process.ProcessName);
}
}

How do I make here please something like:
if(Session.Process!=thisProcess) {/*mute process*/}

Is it this one:

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.getcurrentprocess?view=net-6.0

?

EDIT: I have everything working except I need a way as I can't find it: session.Process.Mute(); something like this that I can't find.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900