Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
773 views
in Technique[技术] by (71.8m points)

audio - How to set volume of a SourceDataLine in Java

I'm trying to make an mp3 player in java and I can`t figure out how to control the volume in it.

I've tried something like this:

         // Adjust the volume on the output line.
         if (dataLine.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
             FloatControl volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN);
            volume.setValue(100.0F);
         }

Everything I have written until this code worked fine but apparently the dataLine is NOT control Supported because it jumps over this IF statement.

My question is this : Do you have any idea why this is happening and how could I work this issue around so that I could control the volume of my application?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OK GUYS,

I found my mess-up. I actually forgot to call the dataLine.open(audioFormat) function which acquires the system resources.

So the code workes just fine, in case anyone has this kind of problems too


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...