title: How do I correctly use FloatControl with the Java Sound API?
body: <p>I am currently writing a test program in <code>Java</code> that I want to be able to control my computer's main SPEAKER with a <code>JSlider</code> on a GUI application. I have read through <a href="http://docs.oracle.com/javase/tutorial/sound/accessing.html" rel="nofollow">this</a> page on the AudioSystem class and <a href="http://docs.oracle.com/javase/tutorial/sound/controls.html" rel="nofollow">this</a> page on Controls. It is my understanding that I need to get a Port or line through a mixer and then institute a Control on that line or port. Since I am controlling volume I need to implement a <code>FloatControl</code>. My program compiles with no problem, however when I run it and adjust the JSlider I get sent the error message under the <code>catch</code> clause.</p>
  
  <p>This is my test program:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.io.IOException;
  
  import javax.sound.sampled.AudioSystem;
  import javax.sound.sampled.FloatControl;
  import javax.sound.sampled.Mixer;
  import javax.sound.sampled.Port;
  import javax.swing.JFrame;
  import javax.swing.JSlider;
  import javax.swing.event.ChangeEvent;
  import javax.swing.event.ChangeListener;
  
  public class speakerWork2
  {
      public static void main(String [] args)throws IOException
      {
          Frame speaker = new Frame();
      }
  }
  
  class Frame extends JFrame
  {
      JSlider mainVolume = new JSlider(JSlider.VERTICAL,0,100,50);
  
      public Frame()
      {
          super();
          setVisible(true);
          setResizable(false);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setLayout(new BorderLayout());
          setSize(100, 450);
          setLocation(300,200);
  
          add(mainVolume);
  
          mainVolume.addChangeListener(new mainVolumeHandler());
      }
  
      public class mainVolumeHandler implements ChangeListener
      {
          int sliderVal = mainVolume.getValue();
  
          public void setValue(FloatControl sliderVal) 
          {
          }
  
          public void stateChanged(ChangeEvent f)
          {
              Port SPEAKER;  
              FloatControl volCtrl;  
              try 
              {  
                  Mixer mixer = AudioSystem.getMixer(null);  
                  SPEAKER = (Port)mixer.getLine(Port.Info.SPEAKER);  
                  SPEAKER.open();  
                  volCtrl = (FloatControl) SPEAKER.getControl(  
                          FloatControl.Type.VOLUME);  
              } 
              catch (Exception e) 
              {  
                  System.out.println("Failed trying to find SPEAKER"  
                          + " VOLUME control: exception = " + e);  
              }
          }
      }
  }
  </code></pre>
  
  <p>When I run the above program, exception e prints: </p>
  
  <pre><code>java.lang.IllegalArgumentException: Line unsupported: SPEAKER target port
  </code></pre>
  
  <p>When I query my computer for mixers, lines and ports I get the following result for my Speakers...</p>
  
  <pre><code>mixer name: Port Speakers / Headphones (IDT High Definition Audio CODEC)
  Line.Info: SPEAKER target port
  volCtrl.getValue() = 1.0
  </code></pre>
  
  <p>What am I doing wrong, and what do I need to do to correct myself?</p>