Search in sources :

Example 1 with Port

use of javax.sound.sampled.Port in project smarthome by eclipse.

the class JavaSoundAudioSink method runVolumeCommand.

private 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;
            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);
            }
        }
    }
}
Also used : Mixer(javax.sound.sampled.Mixer) Port(javax.sound.sampled.Port) LineUnavailableException(javax.sound.sampled.LineUnavailableException) FloatControl(javax.sound.sampled.FloatControl)

Example 2 with Port

use of javax.sound.sampled.Port in project Spark by igniterealtime.

the class JavaMixer method createMixerChildren.

private void createMixerChildren(JavaMixer.MixerNode mixerNode) {
    Mixer mixer = mixerNode.getMixer();
    Line.Info[] infosToCheck = getPortInfo(mixer);
    for (Line.Info anInfosToCheck : infosToCheck) {
        if (mixer.isLineSupported(anInfosToCheck)) {
            Port port = null;
            DataLine dLine = null;
            int maxLines = mixer.getMaxLines(anInfosToCheck);
            // Workaround to prevent a JVM crash on Mac OS X (Intel) 1.5.0_07 JVM
            if (maxLines > 0) {
                try {
                    if (anInfosToCheck instanceof Port.Info) {
                        port = (Port) mixer.getLine(anInfosToCheck);
                        port.open();
                    } else if (anInfosToCheck instanceof DataLine.Info) {
                        dLine = (DataLine) mixer.getLine(anInfosToCheck);
                        if (!dLine.isOpen()) {
                            dLine.open();
                        }
                    }
                } catch (LineUnavailableException e) {
                // Do Nothing
                } catch (Exception e) {
                // Do Nothing
                }
            }
            if (port != null) {
                JavaMixer.PortNode portNode = new JavaMixer.PortNode(port);
                createPortChildren(portNode);
                mixerNode.add(portNode);
            } else if (dLine != null) {
                JavaMixer.PortNode portNode = new JavaMixer.PortNode(dLine);
                createPortChildren(portNode);
                mixerNode.add(portNode);
            }
        }
    }
}
Also used : Mixer(javax.sound.sampled.Mixer) Port(javax.sound.sampled.Port) DataLine(javax.sound.sampled.DataLine) LineUnavailableException(javax.sound.sampled.LineUnavailableException) LineUnavailableException(javax.sound.sampled.LineUnavailableException) DataLine(javax.sound.sampled.DataLine) Line(javax.sound.sampled.Line)

Aggregations

LineUnavailableException (javax.sound.sampled.LineUnavailableException)2 Mixer (javax.sound.sampled.Mixer)2 Port (javax.sound.sampled.Port)2 DataLine (javax.sound.sampled.DataLine)1 FloatControl (javax.sound.sampled.FloatControl)1 Line (javax.sound.sampled.Line)1