1

I am using the following code of answer 2 to mute external players like vlc or windows media player.

Controlling Application's Volume: By Process-ID

The VLC player is muted properly. But windows media player does not.

Visually it is mutated correctly as shown in the following image. But I still hear the sound through the speakers. When I remove the mute (mute of the application) and I put it manually using the mouse it is muted correctly.

enter image description here

enter image description here

       public static void mute()
        {              

            for(int i = 0;i<playerList.Length;i++)
            {                    
                var hWnd = FindWindow(null, playerList[i]);
                if (hWnd == IntPtr.Zero)
                {
                    Console.WriteLine("Mute " + playerList[i] + " Error_1");
                    continue;
                }


                uint pID;
                GetWindowThreadProcessId(hWnd, out pID);
                if (pID == 0)
                {
                    Console.WriteLine("Mute " + playerList[i] + " Error_2");
                    continue;
                }




                VolumeMixer.SetApplicationMute((int)pID, true);
                Console.WriteLine("Mute " + playerList[i] + " Ok PID: " + pID);


            }


        }
Community
  • 1
  • 1
user2983041
  • 1,761
  • 4
  • 19
  • 31
  • It may not be relevant, but i once wrote a tool for the WMP and had similar issues with controlling the volume level. It turned out that the WMP had always more than one audio session, so i had to set the volume on each of those sessions. You may need to change the implementation of the 'VolumeMixer' class in a way that every session with the WMP process id is muted. – Streamline Feb 05 '17 at 19:04
  • I have performed the following test: I have obtained all running processes "Process.GetProcesses()" and I have mute the volume of all process. The same problem happens. The bar is lowered but I'm still listening. – user2983041 Feb 05 '17 at 19:27
  • That's not exactly what i meant. In the `GetVolumeObject(int pid)` method: instead of returning only one session volume control, one may have to return a list containing all `ISimpleAudioVolume` that have the process id of the WMP and set the mute state on all of them. – Streamline Feb 05 '17 at 19:56
  • It works perfectly. – user2983041 Feb 05 '17 at 23:57

1 Answers1

0

@Streamline said in comment:

In the GetVolumeObject(int pid) method: instead of returning only one session volume control, one may have to return a list containing all ISimpleAudioVolume that have the process id of the WMP and set the mute state on all of them.

That was the problem. Now it works perfectly.

user2983041
  • 1,761
  • 4
  • 19
  • 31