Question

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.

Was it helpful?

Solution

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 );
}

OTHER TIPS

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 :-(

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top