How to programmatically set volume in Windows, Mac and Ubuntu?

后端 未结 3 1591
小鲜肉
小鲜肉 2020-12-10 10:04

I\'d like to programmatically set volume in Windows, Mac and Ubuntu using C/C++. Command line also can but C/C++ preferred. Thank you in advance!

相关标签:
3条回答
  • 2020-12-10 10:09

    For Linux using ALSA sound system, you can use following command:

    amixer set Master 50%
    
    0 讨论(0)
  • 2020-12-10 10:28

    For completeness sake, here is the OSX cli version:

    osascript -e "set volume output volume (output volume of (get volume settings)+2)"
    

    And on the C side it's more difficult. From everything I found researching this, the easiest way is using one of the readily available objective C answers and wrapping them into a function in an extra object you can call from C/C++.

    0 讨论(0)
  • 2020-12-10 10:36

    Just a hint, In windows the 'philosophy' around volume adjustment has changed between XP and Vista/7. Code that would change the master volume on XP will only change the application specific volume setting in the mixer on Vista and 7.

    Here is a good blog post by one of the MS audio dev team regarding this: Larry Osterman's Blog

    Here are some codeproject pages that might prove useful:

    For XP

    For Vista +

    Also, there are a few powerpoint presentations regarding the new api's here: AMP Summit ppts. The Audio Endpoints in Windows Vista presentation has some good info.

    As for OsX and Ubuntu, i have no idea.

    0 讨论(0)
提交回复
热议问题