如何在Java中设置SourceDataLine的卷

我正在尝试在java中制作一个MP3播放器而我无法弄清楚如何控制其中的音量.

我尝试过这样的事情:

         // Adjust the volume on the output line.
         if (dataLine.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
             FloatControl volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN);
            volume.setValue(100.0F);
         }

我写的所有东西,直到这段代码工作正常,但显然dataLine不是控制支持因为它跳过这个IF语句.

我的问题是:你知道为什么会这样,我怎么能解决这个问题,以便控制我的应用程序量?

解决方法:

您是否尝试过查看dataLine.getControls()将返回的内容?

Obtains the set of controls associated
with this line. Some controls may only
be available when the line is open. If
there are no controls, this method
returns an array of length 0.

如果你想要卷,你不想测试FloatControl.Type.VOLUME控件吗?

上一篇:自定义Java Swing Meter控件


下一篇:JavaFX:将UI控件添加到TreeTableView