Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can I control system's volume with java?

Squall867May 12 2012 — edited Apr 12 2013
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?:(
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 10 2013
Added on May 12 2012
4 comments
9,712 views