can i control the volume for each application like the volume mixer panel of windows..?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
thaos
Posts: 22
Joined: 18 Feb 2020, 02:38

can i control the volume for each application like the volume mixer panel of windows..?

Post by thaos » 15 Aug 2022, 12:15

I used a lib to try, but failed.
The following is that.
va.ahk https://autohotkey.com/board/topic/21984-vista-audio-control-functions/

Code: Select all

#Include va.ahk
WinGet, winpid, pid, % "ahk_exe msedge.exe"
MsgBox, % GetAppVolume(winpid)
Sleep, 1000
exitapp
; set the master volume about the window
; vol is 0-100, can be signed
setWndVol(vol, winTitle := "a"){
	winGet, winPid, PID, % winTitle
	if !(volume := GetVolumeObject(winPid))
		return
	vsign := subStr(vol, 1, 1)
	if (vsign = "+" || vsign = "-") {
		vol := subStr(vol, 2)
		VA_ISimpleAudioVolume_GetMasterVolume(volume, cvol)
		cvol *= 100
		vol := Round(cvol + vol)
		if(vol > 100)
			vol := 100
	}
	VA_ISimpleAudioVolume_SetMasterVolume(volume, vol / 100)
    objRelease(volume)
}
; return master volume about the window
; return 0-100
getWndVol(winTitle := "a"){
    winGet, winPid, PID, % winTitle
	if(!volume := GetVolumeObject(winPid))
		return
    VA_ISimpleAudioVolume_GetMasterVolume(volume, cvol)
	objRelease(volume)
    return Round(cvol * 100)
}
The above script worked for most of applications, but did not for some, especially ms edge with youtube video.
I guess the reason why the edge manages many complex sub processes.
On the other hand, the volume mixer panel of Windows could control the volume of edge properly.
How can I treat volumes like the volume mixer panel..?
Thanks in advance for your help.

thaos
Posts: 22
Joined: 18 Feb 2020, 02:38

Re: can i control the volume for each application like the volume mixer panel of windows..?

Post by thaos » 16 Aug 2022, 15:28

omg I forgot a function..sorry.
I dont remember where I got it, maybe this forum.

Code: Select all

GetVolumeObject(Param = 0)
{
    static IID_IASM2 := "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}"
    , IID_IASC2 := "{bfb7ff88-7239-4fc9-8fa2-07c950be9c6d}"
    , IID_ISAV := "{87CE5498-68D6-44E5-9215-6DA47EF883D8}"
    
    ; Get PID from process name
    if Param is not Integer
    {
        Process, Exist, %Param%
        Param := ErrorLevel
    }
    
    ; GetDefaultAudioEndpoint
    DAE := VA_GetDevice()
    
    ; activate the session manager
    VA_IMMDevice_Activate(DAE, IID_IASM2, 0, 0, IASM2)
    
    ; enumerate sessions for on this device
    VA_IAudioSessionManager2_GetSessionEnumerator(IASM2, IASE)
    VA_IAudioSessionEnumerator_GetCount(IASE, Count)
    
    ; search for an audio session with the required name
    Loop, % Count
    {
        ; Get the IAudioSessionControl object
        VA_IAudioSessionEnumerator_GetSession(IASE, A_Index-1, IASC)
        
        ; Query the IAudioSessionControl for an IAudioSessionControl2 object
        IASC2 := ComObjQuery(IASC, IID_IASC2)
        ObjRelease(IASC)
        
        ; Get the session's process ID
        VA_IAudioSessionControl2_GetProcessID(IASC2, SPID)
        
        ; If the process name is the one we are looking for
        if (SPID == Param)
        {
            ; Query for the ISimpleAudioVolume
            ISAV := ComObjQuery(IASC2, IID_ISAV)
            
            ObjRelease(IASC2)
            break
        }
        ObjRelease(IASC2)
    }
    ObjRelease(IASE)
    ObjRelease(IASM2)
    ObjRelease(DAE)
    return ISAV
}

thaos
Posts: 22
Joined: 18 Feb 2020, 02:38

Re: can i control the volume for each application like the volume mixer panel of windows..?

Post by thaos » 20 Aug 2022, 09:51

never mind. I solved it by searching all of subprocesses.

Post Reply

Return to “Ask for Help (v1)”