1

Possible Duplicate:
Controlling volume in a java application

i'm looking for help how to get the control of the volume of the computer from an application. I already have seen samples in other posts like:

Port lineIn = null;
    FloatControl volCtrl = null;
    try {
        Mixer mixer = AudioSystem.getMixer(null);
        lineIn = (Port) mixer.getLine(Port.Info.LINE_IN);
        lineIn.open();
        volCtrl = (FloatControl) lineIn
                .getControl(FloatControl.Type.MASTER_GAIN);
        volCtrl.setValue(volCtrl.getValue() + 10f);
    } catch (Exception e) {
        System.out.println("Failed trying to find LINE_IN"
                + " VOLUME control: exception = " + e);
        lineIn.close();
    }

This example is taken from Oracle page But it throws an exception...

java.lang.IllegalArgumentException: Line unsupported: LINE_IN source port
at com.sun.media.sound.DirectAudioDevice.getLine(Unknown Source)
at core.ProtocolHandler.volumeUp(ProtocolHandler.java:223)
at core.ProtocolHandler.answer(ProtocolHandler.java:211)
at core.Server.run(Server.java:77)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at core.ProtocolHandler.volumeUp(ProtocolHandler.java:230)
at core.ProtocolHandler.answer(ProtocolHandler.java:211)
at core.Server.run(Server.java:77)
at java.lang.Thread.run(Unknown Source)

I have also tried out THIS example....but it throws me the same exception.

Community
  • 1
  • 1
Emaborsa
  • 2,360
  • 4
  • 28
  • 50
  • sorry, i haven't seen that post.... – Emaborsa May 10 '12 at 08:41
  • Are you trying to control the volume of a SourceDataLine? Or something else? On what line is the exception thrown? Does your default sound system have a Line In port? – Phil Freihofner May 11 '12 at 08:24
  • I'm trying to gain the main control volume of my computer. I've tryied using VOLUME, GAIN_MASTER and other too, but i get always the same exception. I just want to control the main volume... – Emaborsa May 11 '12 at 17:15
  • 2
    IMHO this is NOT an exact duplicate. The somewhat *stale* question cited as a duplicate is trying to change the volume of a running Java Application from within that application. This question asks how to affect the computer's volume globally (for anything running on the computer), does it not? I don't have the rep points to give it a reopen however. Just my two cents. Also, would like to point out that even if I have misinterpreted the question, there is enough variation between OS and client computers that "correct" answers can diverge significantly. – Phil Freihofner May 11 '12 at 20:27
  • I *might* be able to add some insight, but I don't know which line in your code is throwing the exception. Also, it would be helpful to know your OS, soundcard, and that sort of thing, so we can take a closer look at the default mixer and whether it even supports the port you are trying to access. – Phil Freihofner May 11 '12 at 20:33
  • Well, i have a Gigabyte mobo with integrated audio...but i think librries works on almost all devices in the same way, it shouldn't depend on the hardware...or does it? I checked which line throws the esception and it is the lineIn = (Port) mixer.getLine(Port.Info.LINE_IN); – Emaborsa May 11 '12 at 21:01
  • The lines that are available do depend on hardware, I think. You can maybe try the two commands mixer.getSourceLineInfo and mixer.getTargetLineInfo. This will tell you what lines are available on your default mixer. You might also check to see what other mixers you have and if you should use one of them. The Exception is telling us that the specified line isn't supported by your default mixer. Maybe that will uncover some clues. Is your app also making a sound? Sometimes with Linux systems, another app will lock the sound system and not release it to let Java get to it. – Phil Freihofner May 12 '12 at 01:32
  • Sorry for delay. Currently i have no time, but ASAP i'll try and let you know. – Emaborsa May 18 '12 at 10:24

0 Answers0