【问题标题】:Java: Master Gain not supported exceptionJava:不支持主增益异常
【发布时间】:2009-12-01 17:13:43
【问题描述】:

在 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 中它可以工作。

谢谢,马丁。

【问题讨论】:

  • 这似乎是您正在使用的“dataLine”实现的问题。数据线的类型是什么?我希望 getControl() 仅在 isControlSupported 返回 false 时抛出此异常...
  • 有可能你的dataLine不是windows和linux中同类型的dataline。通过调试此代码,您可以在 Linux 和 Windows 中调查 dataLine 的类型(它是 SourceDataLine 的子类型)。
  • 是的,是同一种线。

标签: java linux audio volume


【解决方案1】:

在尝试对其使用控件之前,您能否尝试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 );
}

【讨论】:

    【解决方案2】:

    它似乎因 JRE 版本而异。

    我遇到了类似的问题,当我检查 dataLine.getControls() 时,我在 Oracle JDK 1.7 上得到一个“MASTER_GAIN”控件,在 OpenJDK 1.6 上得到一个“音量”控件。更糟糕的是……“音量”的线性值是 0...65536,而 MASTER_GAIN 似乎有分贝设置。

    这么多代码一次,到处运行:-(

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-02
      • 1970-01-01
      相关资源
      最近更新 更多