Code: Select all
Procedure ProcessEnumeratedSessions(pSessionManager.IAudioSessionManager2)
Protected pSessionList.IAudioSessionEnumerator
Protected pSessionControl.IAudioSessionControl
Protected pSessionControl2.IAudioSessionControl2
Protected sessionEvents.IAudioSessionEvents
Protected index, cbSessionCount, pSessionId, sessionId, PID, NewState, fname.s
If pSessionManager\GetSessionEnumerator(@pSessionList) <> #S_OK
Debug "Get Session List Error"
EndIf
If pSessionList\GetCount(@cbSessionCount) <> #S_OK
Debug "Get Session Count Error"
EndIf
For index = 0 To cbSessionCount - 1
pSessionList\GetSession(index, @pSessionControl)
If pSessionControl\QueryInterface(?IID_IAudioSessionControl2, @pSessionControl2) = #S_OK
pSessionControl2\GetProcessId(@PID)
pSessionControl2\GetState(@NewState)
pSessionControl2\GetSessionIdentifier(@pSessionId)
If pSessionId
fname = GetFilePart(StringField(StringField(PeekS(pSessionId, -1, #PB_Unicode), 2, "|"), 1, "%"))
EndIf
If PID > 0 And fname <> "PureBasic_Compilation0.exe"
PostEvent(#EventBeginProcessing, #PB_Ignore, #PB_Ignore, #PB_Ignore, 500)
Debug "New audio session created. PID: " + Str(PID)
;Debug GetFilePart(StringField(StringField(PeekS(pSessionId, -1, #PB_Unicode), 2, "|"), 1, "%"))
Select NewState
Case #AudioSessionStateInactive
Debug Str(PID) + " Inactive"
Case #AudioSessionStateActive
Debug Str(PID) + " Active"
Case #AudioSessionStateExpired
Debug Str(PID) + " Expired"
EndSelect
sessionEvents = CreateMyAudioSessionEvents(PID, pSessionId, pSessionControl2)
pSessionControl2\RegisterAudioSessionNotification(sessionEvents)
pSessionControl2\Release()
EndIf
pSessionControl\Release()
EndIf
Next
pSessionList\Release()
EndProcedure