How to set volume of a SourceDataLine in Java

前端 未结 3 1696
野的像风
野的像风 2021-01-06 05:14

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         


        
相关标签:
3条回答
  • 2021-01-06 06:12
     float vol=50;
    final FloatControl volumeControl = (FloatControl) auline.getControl( FloatControl.Type.MASTER_GAIN );
    volumeControl.setValue( 20.0f * (float) Math.log10( vol / 100.0 ) );
    

    vol=0 means mute.

    0 讨论(0)
  • 2021-01-06 06:13

    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

    0 讨论(0)
  • 2021-01-06 06:13

    Have you tried to see what dataLine.getControls() will return ?

    Obtains the set of controls associated with this line. Some controls may only be available when the line is open. If there are no controls, this method returns an array of length 0.

    If you want volume wouldn't you want to test for the FloatControl.Type.VOLUME control ?

    0 讨论(0)
提交回复
热议问题