示例#1
0
        public static void singleAppVolumeControl()
        {
            AudioSessionManager ASM = new AudioSessionManager();
            int    ans     = 99;
            int    tPid    = 99;
            string proceed = "n";

            ASM.updateActiveAudioSessions();
            ASM.displayActiveAudioSessions();
            do
            {
                Console.Write("enter application number from above list: ");
            } while (!(int.TryParse(Console.ReadLine(), out ans)));
            tPid = ASM.getActiveAudioSessions().ElementAt(ans).ProcessId;
            float vol;

            do
            {
                Console.Write("enter the volume as a percentage(0-100): ");
            } while (!(float.TryParse(Console.ReadLine(), NumberStyles.Number, CultureInfo.InvariantCulture.NumberFormat, out vol)));
            VolumeMixer.SetApplicationVolume(tPid, vol);
            Console.WriteLine("Volume has been Set!");
            Console.Write("Press Enter to continue......");
            proceed = Console.ReadLine();
        }
 /*
  *  Updates the volume of all the running programs in the
  *  program group
  */
 public void updateVolume()
 {
     lock (loadedAudioSessions) {
         if (loadedAudioSessions != null)
         {
             foreach (AudioSession currentAS in loadedAudioSessions.ToList())
             {
                 //AudioSession ash = Program.ASM.getAudioSession(currentAS.Process.ProcessName);
                 VolumeMixer.SetApplicationVolume(currentAS.ProcessId, (float)volAsPercent);
             }
         }
     }
 }