Java:Master Gain 不支持异常

发布于 2024-08-13 02:12:40 字数 696 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沧笙踏歌 2024-08-20 02:12:40

您可以在尝试使用控件之前尝试 open() 该行吗?像这样的东西:

// Added two lines.
DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat );
SourceDataLine dataLine = (SourceDataLine) AudioSystem.getLine( info );
dataLine.open();
// 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 );
}

Could you try to open() the line before trying to use controls on it. Something like this:

// Added two lines.
DataLine.Info info = new DataLine.Info( SourceDataLine.class, audioFormat );
SourceDataLine dataLine = (SourceDataLine) AudioSystem.getLine( info );
dataLine.open();
// 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 );
}
吃素的狼 2024-08-20 02:12:40

看起来它根据 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 :-(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文