fix to psound2 to ignore gaincontrol errors, add linux stuff to faq,

run-expert fix
This commit is contained in:
benfry
2005-05-07 15:59:49 +00:00
parent 8b65a0293c
commit 95c7f78bd8
4 changed files with 55 additions and 38 deletions

View File

@@ -77,8 +77,13 @@ public class PSound2 extends PSound {
clip = (Clip) AudioSystem.getLine(info);
// seems that you can't make more than one of these
gainControl =
(FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
try {
gainControl =
(FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
} catch (Exception e) {
System.err.println("Couldn't get gain control for this .wav file");
e.printStackTrace();
}
// This method does not return until completely loaded
clip.open(ais);
@@ -204,8 +209,12 @@ public class PSound2 extends PSound {
* Set the volume with a value from 0 (off) to 1 (loudest).
*/
public void volume(float v) { // ranges 0..1
float dB = (float)(Math.log(v)/Math.log(10.0)*20.0);
gainControl.setValue(dB);
if (gainControl != null) {
float dB = (float)(Math.log(v)/Math.log(10.0)*20.0);
gainControl.setValue(dB);
} else {
System.err.println("Cannot set the volume for this sound.");
}
}