示例#1
0
        //CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice;


        public int getVolume()
        {
            float?value;

            if (currentMode == MASTER)
            {
                float volume = AudioManager.GetMasterVolume();
                return(Convert.ToInt32(volume));//Convert.ToInt32(defaultPlaybackDevice.Volume);
            }

            else if (currentMode == ESPECIFIC)
            {
                //changeVolume of focused
                String appname = GetActiveWindowTitle();
                IntPtr hwnd    = GetForegroundWindow();
                uint   pid;
                GetWindowThreadProcessId(hwnd, out pid);
                Process p = Process.GetProcessById((int)pid);
                //Console.WriteLine(p.MainWindowTitle);
                int pid1 = p.Id;
                //appname = "Spotify";

                value = VolumeHandler.GetApplicationVolume(pid1);
                return(Convert.ToInt32(value));
            }

            else if (currentMode == CHOOSE)
            {
                String    appname   = chosenAPP;
                int       id        = 0;
                Process[] processes = Process.GetProcesses();
                foreach (Process p in processes)
                {
                    if (p.ProcessName == chosenAPP && !String.IsNullOrEmpty(p.MainWindowTitle))
                    {
                        id = p.Id;
                        break;
                    }
                }


                value = VolumeHandler.GetApplicationVolume(id);
                return(Convert.ToInt32(value));
            }


            return(0);
        }
示例#2
0
        public void changeVolume(int value)
        {
            if (currentMode == MASTER)
            {
                AudioManager.SetMasterVolume(value);
                currentValue = value;
            }

            else if (currentMode == ESPECIFIC)
            {
                //changeVolume of focused
                if (value != currentValue)
                {
                    String appname = GetActiveWindowTitle();
                    IntPtr hwnd    = GetForegroundWindow();
                    uint   pid;
                    GetWindowThreadProcessId(hwnd, out pid);
                    Process p = Process.GetProcessById((int)pid);
                    //Console.WriteLine(p.MainWindowTitle);
                    int pid1 = p.Id;
                    //appname = "Spotify";
                    VolumeHandler.SetApplicationVolume(pid1, value);
                    currentValue = value;
                }
            }

            else if (currentMode == CHOOSE)
            {
                if (value != currentValue)
                {
                    String    appname   = chosenAPP;
                    int       id        = 0;
                    Process[] processes = Process.GetProcesses();
                    foreach (Process p in processes)
                    {
                        if (p.ProcessName == chosenAPP && !String.IsNullOrEmpty(p.MainWindowTitle))
                        {
                            id = p.Id;
                        }
                    }

                    VolumeHandler.SetApplicationVolume(id, value);
                    currentValue = value;
                }
            }
        }