在 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:Master Gain 不支持异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1827607/