Controlling volume in a java application

后端 未结 2 865
长发绾君心
长发绾君心 2021-01-18 19:42

I am fairly new at java. I need to control volume (volume up/down, mute) in a java application. I couldn\'t find a way to do this. I am developing on a linux system (for inf

相关标签:
2条回答
  • 2021-01-18 20:01

    I don't think there is a constant called VOLUME. Its MASTER_GAIN. So you should do

    volCtrl = (floatControl) lineIn.getControl(FloatControl.Type.MASTER_GAIN);
    volCtrl.setValue(you_custom_value);
    
    0 讨论(0)
  • 2021-01-18 20:13

    Sometimes the controls are nested, which makes a platform independent solution difficult. I have written an utility class which is used like that:

    Audio.setMasterOutputVolume(0.5f);
    

    Source code is here: https://github.com/Kunagi/ilarkesto/blob/master/src/main/java/ilarkesto/media/Audio.java

    Stackoverflow users can use the code from Audio.java under the terms of the WTFPL.

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