CSCore Application Audio Mixer Name+Peak

北战南征 提交于 2019-12-04 19:08:51

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;
            }
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!