Exemplo n.º 1
0
        public static List <AppDetails> AllApps()
        {
            var appDetailsList = new List <AppDetails>();

            //Create master volume object
            var masterDetails = new AppDetails();

            masterDetails.App       = "Master Volume";
            masterDetails.Volume    = AudioLibrary.GetMasterVolume();
            masterDetails.Mute      = AudioLibrary.MasterMuteState();
            masterDetails.ProcessId = 0;
            appDetailsList.Add(masterDetails);

            //Find all other active audio processes
            foreach (var ctl in AudioLibrary.EnumerateApplications())
            {
                var appDetails = new AppDetails();
                ctl.GetDisplayName(out string dn);
                ctl.GetProcessId(out uint retval);
                //Process Id 0 is system sounds, currently being ignored until can be handled properly
                if (retval == 0)
                {
                    continue;
                }
                appDetails.ProcessId = retval;
                //If audio process description does not exist, use the app process name
                if (string.IsNullOrEmpty(dn))
                {
                    var p = Process.GetProcessById(Convert.ToInt32(retval));
                    appDetails.App = p.MainWindowTitle;
                }
                else
                {
                    appDetails.App = dn;
                }
                appDetails.Volume = AudioLibrary.GetApplicationVolume(ctl);
                appDetails.Mute   = AudioLibrary.AppMuteState(ctl);
                appDetailsList.Add(appDetails);
            }
            return(appDetailsList);
        }