Java:Master Gain 不支持异常
在 Linux 中,此代码不起作用:我添加了两行
// Added two lines.
DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat );
SourceDataLine dataLine = (SourceDataLine) AudioSystem.getLine( info );
// Adjust the volume on the output line.
if( dataLine.isControlSupported( FloatControl.Type.MASTER_GAIN)) {
// If inside this if, the Master_Gain must be supported. Yes?
FloatControl volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN);
// This line throws an exception. "Master_Gain not supported"
volume.setValue( 100.0F );
}
这正常吗?我该怎么做才能解决这个问题?
在 Windows 中它可以工作。
谢谢,Martijn。
In linux this code doesn't work: I added two lines
// Added two lines.
DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat );
SourceDataLine dataLine = (SourceDataLine) AudioSystem.getLine( info );
// Adjust the volume on the output line.
if( dataLine.isControlSupported( FloatControl.Type.MASTER_GAIN)) {
// If inside this if, the Master_Gain must be supported. Yes?
FloatControl volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN);
// This line throws an exception. "Master_Gain not supported"
volume.setValue( 100.0F );
}
Is this normal? What do I have to do to solve this?
In windows does it work.
Thanks, Martijn.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在尝试使用控件之前尝试
open()
该行吗?像这样的东西:Could you try to
open()
the line before trying to use controls on it. Something like this:看起来它根据 JRE 版本而有所不同。
我遇到了类似的问题,当我检查 dataLine.getControls() 时,我在 Oracle JDK 1.7 上得到一个“MASTER_GAIN”控件,在 OpenJDK 1.6 上得到一个“Volume”控件。更糟糕的是……“音量”具有 0...65536 的线性值,而 MASTER_GAIN 似乎具有分贝设置。
代码一次,到处运行就这么多了:-(
It looks like it differs depending on the JRE version.
I'm having a similar problem and when I check dataLine.getControls(), I get a "MASTER_GAIN" Control on Oracle JDK 1.7 and a "Volume" Control on OpenJDK 1.6. And what makes it worse ... the "Volume" has a linear value from 0...65536 while the MASTER_GAIN seems to have a decibel setting.
So much for code once, run everywhere :-(