控制Java应用程序的音频

时间:2012-05-09 20:37:08

标签: java audio

  

可能重复:
  Controlling volume in a java application

我正在寻求帮助如何从应用程序控制计算机的音量。我已经在其他帖子中看过样本,如:

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();
    }

此示例取自Oracle页面 但它引发了一个例外...

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)

我也尝试了THIS示例....但它会抛出同样的异常。

0 个答案:

没有答案