Getting the system audio levels in Java

前端 未结 4 1156
故里飘歌
故里飘歌 2021-01-13 19:15

How does one get the master volume in Java? I want to make a program that displays (NOT CHANGE) this value (probably on a JProgressBar or somet

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 19:36

    You could be a little less abrasive rather than say "Does not help me".

    Otherwise, here is the big picture, using the Sound API mentioned by AlexR's example: (there are a lot of practical details on that forum thread, and there is some Oracle documentation for Processing Audio with Controls)

    • Once you get a Line object that represents the sound output line that you wish to control, it is rather trivial to get the volume control:

      line.open(); // May be necessary if the line is not already opened.
      FloatControl volumeControl = (FloatControl) masterLine.getControl(FloatControl.Type.VOLUME);
      
    • Getting the "Master Line" object is, at best, platform-dependant. You will have to list the Mixers and the Lines at runtime using the AudioSystem static methods in order to determine which line you want. It can also happen that the master line will not support the volume control directly, but only through a CompoundControl. (through a hierarchy that is, you guessed it, platform-dependant).

提交回复
热议问题