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