How to programmatically get the current audio level?

前端 未结 3 1670
梦谈多话
梦谈多话 2020-12-31 09:31

Basically, what I need is a way to tap into the current audio output and check the sound level, i.e. I need to be able to check whether there is something playing on the aud

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 10:07

    Here is a helpful link for Windows API invokations, and here's exactly what you are looking for:

    http://www.pinvoke.net/default.aspx/winmm.waveOutGetVolume


    Since the requirement changed and you don't need the audio level I suggest the following might help:

    I think you need to read what is being playedback on the output stream and by analyzing the data in some algorithms you might be able to decide weather something is being playedback or not. To do this you need the MMDevice API

    http://msdn.microsoft.com/en-us/library/dd316556(v=VS.85).aspx

    I don't want to discorage you but believe me this is not going to be easy to accomplish if you are not familiar with unmanaged code.

    • You have to fill many structures in each invokation.
    • You have to perform invokations in specific order.
    • Marshalling references to structures.

    And even if you accomplish that you can't anticipate the outcome behavior of the device. Good luck.

提交回复
热议问题