问题描述
我尝试获取processID的峰值(win7音频混音器中绿色条的电平),例如5640-Spotify.
i try to get the peak(the level of the green bar in the audio mixer of win7) of a processID for example 5640 - Spotify.
在Internet上搜索了一个好的图书馆.我找到了CSCore.
Searched at the Internet for a good library. I found CSCore.
现在我有这个了
class Program
{
static void Main(string[] args)
{
using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
{
using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
{
foreach (var session in sessionEnumerator)
{
using (var audioMeterInformation = session.QueryInterface<AudioMeterInformation>())
{
Console.WriteLine(audioMeterInformation.GetPeakValue()*100);
}
}
}
}
Console.ReadKey();
}
private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
{
using (var enumerator = new MMDeviceEnumerator())
{
using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
{
Debug.WriteLine("DefaultDevice: " + device.FriendlyName);
var sessionManager = AudioSessionManager2.FromMMDevice(device);
return sessionManager;
}
}
}
}
}
http://cscore.codeplex.com/的文档对我没有帮助.有人可以用我的代码给我一个例子,我如何获得这样的输出:
The Documentation of http://cscore.codeplex.com/ doesn't helped me. Can someone give me an example with my code, how i can get an output like this:
58,31232 ---进程ID --- Spotify
58,31232---Process-ID---Spotify
此刻,它看起来像这样:
At the Moment it looks like this:
推荐答案
您可以将代码修改为类似以下内容(还可以查看cscore的单元测试):
You can modify your code to something like this (also take a look at the unit-tests of cscore):
class Program
{
static void Main(string[] args)
{
using (var sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render))
using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
{
foreach (var session in sessionEnumerator)
{
Assert.IsNotNull(session);
using (var session2 = session.QueryInterface<AudioSessionControl2>())
using (var audioMeterInformation = session.QueryInterface<AudioMeterInformation>())
{
Debug.WriteLine("Process: {0}; Peak: {1:P}",
session2.Process == null ? String.Empty : session2.Process.MainWindowTitle,
audioMeterInformation.GetPeakValue()*100);
}
}
}
Console.ReadKey();
}
private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
{
using (var enumerator = new MMDeviceEnumerator())
{
using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
{
Debug.WriteLine("DefaultDevice: " + device.FriendlyName);
var sessionManager = AudioSessionManager2.FromMMDevice(device);
return sessionManager;
}
}
}
}
这篇关于CSCore应用程序音频混音器名称+峰值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!