1

I need to know what should i use for controlling volume in MP3 player which I've created using jLayer? Which API or Methods I can use to control volume of mp3 file ?

Anand Chokshi
  • 17
  • 1
  • 7
  • Does his help: [Audio volume control (increase or decrease) in Java](http://stackoverflow.com/questions/953598/audio-volume-control-increase-or-decrease-in-java)? – Gerold Broser Sep 26 '14 at 22:22
  • @GeroldBroser:it only works for wav, i need something like this but for mp3. Thanks though. – Anand Chokshi Sep 27 '14 at 05:24
  • The linked answer works for any type of audio file once the decoder has been connected to the Javasound API using SPI (which the JLayer MP3 code supports). – greg-449 Sep 27 '14 at 07:19
  • @greg-449: Can you explain some more, that would be great help? – Anand Chokshi Sep 28 '14 at 09:03
  • Use the `mp3spi` library http://www.javazoom.net/mp3spi/sources.html to install jLayer in to JavaSound. See the readme.txt in the download. – greg-449 Sep 28 '14 at 09:30
  • @greg-449: I have imported mp3spi library as you mentioned but still I m getting "javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file" for mp3 file on linked code that you mentioned. – Anand Chokshi Sep 30 '14 at 22:50

1 Answers1

0
  public class VolumeSlider{
 // to get the aydiosystem gain control
     public void setGain(float ctrl)  
    {          
        try {  
        Mixer.Info[] infos = AudioSystem.getMixerInfo();    
        for (Mixer.Info info: infos)    
        {    
           Mixer mixer = AudioSystem.getMixer(info);  
           if (mixer.isLineSupported(Port.Info.SPEAKER))    
           {    
              Port port = (Port)mixer.getLine(Port.Info.SPEAKER);    
              port.open();    
              if (port.isControlSupported(FloatControl.Type.VOLUME))    
              {    
                 FloatControl volume =  (FloatControl)port.getControl(FloatControl.Type.VOLUME);                    
                 volume.setValue(ctrl);  
              }    
              port.close();    
           }    
         }    
        } catch (Exception e) {   
            JOptionPane.showMessageDialog(null,"Erro\n"+e);  
        }  
    } 
alex
  • 7
  • 5