如何在 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 语句。
我的问题是:您知道为什么会发生这种情况吗?我该如何解决这个问题,以便我可以控制应用程序的数量?
I'm trying to make an mp3 player in java and I can`t figure out how to control the volume in it.
I've tried something like this:
// 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);
}
Everything I have written until this code worked fine but apparently the dataLine is NOT control Supported because it jumps over this IF statement.
My question is this : Do you have any idea why this is happening and how could I work this issue around so that I could control the volume of my application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,伙计们,
我发现我的混乱了。我实际上忘记调用获取系统资源的 dataLine.open(audioFormat) 函数。
所以代码工作得很好,以防有人也遇到此类问题
OK GUYS,
I found my mess-up. I actually forgot to call the dataLine.open(audioFormat) function which acquires the system resources.
So the code workes just fine, in case anyone has this kind of problems too
您是否尝试过查看
dataLine.getControls()
将返回什么?如果您想要音量,您是否不想测试
FloatControl.Type.VOLUME
控件?Have you tried to see what
dataLine.getControls()
will return ?If you want volume wouldn't you want to test for the
FloatControl.Type.VOLUME
control ?vol=0 表示静音。
vol=0 means mute.