4 Replies Latest reply: Apr 12, 2013 7:28 AM by PhHein RSS

    How can I control system's volume with java?

    Squall867
      Hi, I'm trying to make a remote audio control and I need a way to set current volume by code.

      After looking at java sound APIs I came up with this:
      line = mixer.getLine(lineInfo);
      boolean opened = line.isOpen() || line instanceof Clip;
      if(!opened){
           System.out.println("Line is not open, trying to open it...");
           line.open();
           opened = true;
      }
      if(line.isControlSupported(FloatControl.Type.VOLUME)){
                FloatControl volumeCtrl = (FloatControl)line.getControl(FloatControl.Type.VOLUME);
                     System.out.println("Current volume is: "+volumeCtrl.getValue());
      }
      I tried this code with every mixer I have (althought I think it's the "SPEAKER" one...) but I always get 1.0 as current volume, no matter what.
      So, I'm getting something wrong..can you help me?:(