主增益不支持异常

主增益不支持异常

在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中有效。

谢谢,马丁。

最佳答案

在尝试在该行上使用控件之前,您可以尝试对它进行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 );
}

关于java - Java:主增益不支持异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1827607/

10-11 15:31