Example usage for javax.sound.sampled AudioSystem getMixer

List of usage examples for javax.sound.sampled AudioSystem getMixer

Introduction

In this page you can find the example usage for javax.sound.sampled AudioSystem getMixer.

Prototype

public static Mixer getMixer(final Mixer.Info info) 

Source Link

Document

Obtains the requested audio mixer.

Usage

From source file:org.openhab.io.multimedia.actions.Audio.java

private static void runVolumeCommand(Closure closure) {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    for (Mixer.Info info : infos) {
        Mixer mixer = AudioSystem.getMixer(info);
        if (mixer.isLineSupported(Port.Info.SPEAKER)) {
            Port port;/*from   w  ww. j a va  2s . c  o m*/
            try {
                port = (Port) mixer.getLine(Port.Info.SPEAKER);
                port.open();
                if (port.isControlSupported(FloatControl.Type.VOLUME)) {
                    FloatControl volume = (FloatControl) port.getControl(FloatControl.Type.VOLUME);
                    closure.execute(volume);
                }
                port.close();
            } catch (LineUnavailableException e) {
                logger.error("Cannot access master volume control", e);
            }
        }
    }
}