question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change volume of a currently running program

See original GitHub issue

Is it possible to change the audio volume of a specific session/program (like Firefox)?

My current code allows me to change the volume of a device, but I can’t figure out how to change the volume of a program…

class Program
    {
        static void Main(string[] args)
        {

            try
            {
                MMDeviceEnumerator MMDE = new MMDeviceEnumerator();

                MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active);
                
                foreach (MMDevice dev in DevCol)
                {
                    try
                    {
                            var newVolume = (float)Math.Max(Math.Min(10, 100), 0) / (float)100;
                       
                            dev.AudioEndpointVolume.MasterVolumeLevelScalar = newVolume;

                            Debug.WriteLine("Volume of " + dev.DeviceFriendlyName + " is " + dev.AudioEndpointVolume.MasterVolumeLevelScalar.ToString());
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(dev.DeviceFriendlyName + " could not be muted " + ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error: " + ex.Message);
            }
                            Console.ReadKey();
       }
 }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
roblatourcommented, Aug 16, 2023

Thank you, turns out I was using an older version for the library. Upgrading to 2.1 allow the SimpleAudioVolume property to be set.

0reactions
markheathcommented, Aug 15, 2023

You can set the Volume property on SimpleAudioVolume. The VolumePanel in NAudioDemo does this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows 11: How to Change Sound Volume for Individual ...
If you left click the Sound icon in the notification area, it is possible to change only the master volume. Here is how...
Read more >
How to Adjust Sound Volume for Individual Apps in ...
You can only change the volume for individual apps which are currently open and active. The volume setting changed will be reset if...
Read more >
How to change the volume of different programs with your ...
In terms of a generic application to adjust audio volumes individually, your best bet would be NirSoft Volumouse.
Read more >
How do I change default volume level for programs in ...
1. Open Internet Explorer. · 2. Open Volume Mixer. · 3. Drag the slider below Internet Explorer down to reduce its volume.
Read more >
How to adjust app sound individually on Windows 10
To adjust the sound level for a particular app on Windows 10, open Settings > Sound > App volume and device preferences and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found