gpt4 book ai didi

c# - 从 CSCore audiostream 获取进程名称或 ID

转载 作者:太空宇宙 更新时间:2023-11-03 21:25:30 24 4
gpt4 key购买 nike

我已经使用 CSCore 库从我的程序中过滤了所有音频流。它工作正常,但我不知道哪个流属于哪个进程。有没有办法获取每个流的 processId 或 processname?

我的代码:

public class Audio
{
public static void start(ListBox device, ListBox process)
{
using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
{

using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
{

foreach (var session in sessionEnumerator)
{
using (var audioMeterInformation = session.QueryInterface<AudioMeterInformation>())
{
device.Items.Add(audioMeterInformation.GetPeakValue());

process.Items.Add("here I need the processname or ID");
}
}
}
}


}

private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
{
using (var enumerator = new MMDeviceEnumerator())
{
using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
{
var sessionManager = AudioSessionManager2.FromMMDevice(device);
return sessionManager;
}
}
}
}

非常感谢!

最佳答案

您必须查询 AudioSessionControl2 对象的实例:

public class Audio
{
public static void start(ListBox device, ListBox process)
{
using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
{

using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
{
foreach (var session in sessionEnumerator)
{
using (var audioMeterInformation = session.QueryInterface<AudioMeterInformation>())
using(var session2 = session.QueryInterface<AudioSessionControl2>())
{
device.Items.Add(audioMeterInformation.GetPeakValue());
var processID = session2.ProcessID;
process.Items.Add("here I need the processname or ID");
}
}
}
}


}

private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
{
using (var enumerator = new MMDeviceEnumerator())
{
using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
{
var sessionManager = AudioSessionManager2.FromMMDevice(device);
return sessionManager;
}
}
}
}

关于c# - 从 CSCore audiostream 获取进程名称或 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27297577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com