简体   繁体   中英

get output audio from computer (using c#)

I've been researching this for ages and nothing seems to work for me. I'm using Visual c# and I'm pretty much a beginner. I've been trying to capture the loudness of music playing on the computer while its playing, and put it in some variable I can use in my program.

I know there are lots of questions about this, but none of them have worked for me. The Naudio website isn't helping, and the stuff on the Microsoft website seems to be all in C++?!?

For a windows OS up until Windows XP, you could use pinvoke to get the sound level:

    // Pre Windows Vista
    [DllImport("winmm.dll")]
    public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);

From win vista and up, this part got redesigned and wrapped in the Core Sound API

You might want to take a look at the http://naudio.codeplex.com/ library. They have wrappers for getting the master volume.

    MMDeviceEnumerator DevEnum = new MMDeviceEnumerator();
    MMDevice device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
    int result = (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM