1

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

谢谢,马丁。

4

2 回答 2

3

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 );
}
于 2009-12-01T22:38:08.500 回答
1

看起来它因 JRE 版本而异。

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

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

于 2013-10-23T18:44:04.453 回答