Closed valentimarco closed 11 months ago
Hi @valentimarco,
I'm not sure I understand, but the AudioSessionControl2
is passed as a parameter in the OnSessionCreated
event handler. It's the second parameter (session).
I guess you could write something like this:
var audio = (AudioSessionControl2)session;
audio.OnStateChanged += changestate;
Hi, thx for the response
I can confirm that casting do not work, the program breaks (without crashing) in that line.
In the code as you can see, i call the constructor of AudioSessionControl2
bc i modify the project by putting public the constructor... but i don't think is a good idea, so i asked with this issue if there are some other method to do the same thing...
My bad... it's been a while since I personally used CoreAudio ;)
Looking at the sample code from CoreAudioForms.Framework.Sessions I see that the handler for the OnSessionCreated
does not attach to the OnStateChange
event for that session; instead, it queries the AudioSessionManager2
from the sender and gathers all the sessions from that object and that's where the OnStateChanged
event handler is attached.
Ok, i will try tomorrow! thx
Here's a simplified version of the code from the sample. Hope this helps.
private void HandleSessionCreated(object sender, IAudioSessionControl2 newSession) {
AudioSessionManager2 asm = (AudioSessionManager2)sender;
newSession.GetProcessId(out uint newSessionId);
asm.RefreshSessions();
foreach(var session in asm.Sessions) {
if(session.ProcessID == newSessionId) {
session.OnStateChanged += (s, e) => {
// Your code here
};
break;
}
}
}
Thank you for the Code Snippet, all works flawlessly! i have another question: When AudioSessionManager2 object is (potentially) null in MMDevice object?
Awesome! Glad I could help...
I don't think I have ever encountered AudioSessionManager2 being null and I did test CoreAudio on many, many devices when I was actively developing it.
Hi, first of all thanks for this piece of art! I am writing simple VR mixer and i had been blocked in this part of code, where i need to take the AudioSessionControl2 object connected to a specific Process and insert it in a list. My first idea was to modified the code, by changing the access modifier from internal to public. (But if was written as internal, is there a reason??) Is there a way to get this object without modify the code?
Here the code