use of javax.sound.sampled.Mixer 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.Mixer in project Spark by igniterealtime.
the class JavaMixer method getPortMixers.
/**
* Returns the Mixers that support Port lines.
*
* @return List<Mixer> Port Mixers
*/
private List<Mixer> getPortMixers() {
List<Mixer> supportingMixers = new ArrayList<Mixer>();
Mixer.Info[] aMixerInfos = AudioSystem.getMixerInfo();
for (Mixer.Info aMixerInfo : aMixerInfos) {
Mixer mixer = AudioSystem.getMixer(aMixerInfo);
boolean bSupportsPorts = arePortsSupported(mixer);
if (bSupportsPorts) {
supportingMixers.add(mixer);
}
}
return supportingMixers;
}
use of javax.sound.sampled.Mixer in project ceylon by eclipse.
the class run_ method main.
public static void main(String[] args) throws Exception {
Mixer mixer = AudioSystem.getMixer(null);
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
Type[] fileTypes = AudioSystem.getAudioFileTypes();
boolean moduleHasMixer = mixer != null;
int moduleMixerCount = mixers.length;
int moduleFileTypeCount = fileTypes.length;
System.out.println("Number of mixers/filetypes using Ceylon runtime = " + moduleMixerCount + "/" + moduleFileTypeCount);
boolean plainHasMixer = Boolean.valueOf(System.getProperty("ceylon.runtime.test.services.audiotest.hasmixer"));
if (plainHasMixer != moduleHasMixer) {
throw new AssertionError("Getting default mixer gives different result when obtained from plain Java versus the Ceylon runtime");
}
int plainMixerCount = Integer.valueOf(System.getProperty("ceylon.runtime.test.services.audiotest.mixers"));
if (plainMixerCount != moduleMixerCount) {
throw new AssertionError("Number of mixers not equal when obtained from plain Java versus the Ceylon runtime");
}
int plainFileTypesCount = Integer.valueOf(System.getProperty("ceylon.runtime.test.services.audiotest.filetypes"));
if (plainFileTypesCount != moduleFileTypeCount) {
throw new AssertionError("Number of filetypes not equal when obtained from plain Java versus the Ceylon runtime");
}
System.out.println("Everything OK");
}
use of javax.sound.sampled.Mixer in project ACS by ACS-Community.
the class AlarmSound method play.
/**
* Play the sound for the given priority
*
* @param priority The priority of the alarm
*/
private void play(int priority) throws Exception {
if (priority < 0 || priority > 3) {
throw new IllegalStateException("Invalid alarm priority " + priority);
}
URL url = soundURLs[priority];
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(url);
} catch (Throwable t) {
// If there is an error then the panel does nothing
// It might happen for example if another application
// is locking the audio.
System.err.println(t.getMessage());
t.printStackTrace();
return;
}
// Obtain the information about the AudioInputStream
AudioFormat audioFormat = audioInputStream.getFormat();
SourceDataLine line = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
// Get the list of available mixers
Mixer.Info[] mixersInfo = AudioSystem.getMixerInfo();
// one is available is found
for (int i = 0; i < mixersInfo.length && line == null; i++) {
Mixer.Info mi = mixersInfo[i];
try {
Mixer mixer = AudioSystem.getMixer(mi);
line = (SourceDataLine) mixer.getLine(info);
} catch (LineUnavailableException lue) {
System.err.println("Line unavailable " + lue.getMessage());
line = null;
continue;
} catch (Throwable t) {
System.err.println("Exception getting the line " + t.getMessage());
line = null;
continue;
}
try {
line.open(audioFormat, EXTERNAL_BUFFER_SIZE);
} catch (Throwable t) {
System.err.println("Error opeining the line: " + t.getMessage());
line = null;
continue;
}
try {
line.start();
} catch (Throwable t) {
System.err.println("Error starting the line: " + t.getMessage());
line = null;
continue;
}
try {
playOnLine(line, audioInputStream);
} catch (Throwable t) {
System.err.println("Error playing: " + t.getMessage());
line = null;
continue;
}
// plays what's left and and closes the audioChannel
line.drain();
line.close();
}
}
use of javax.sound.sampled.Mixer in project jdk8u_jdk by JetBrains.
the class DataLine_ArrayIndexOutOfBounds method main.
public static void main(String[] args) throws Exception {
Mixer.Info[] infos = AudioSystem.getMixerInfo();
log("" + infos.length + " mixers detected");
for (int i = 0; i < infos.length; i++) {
Mixer mixer = AudioSystem.getMixer(infos[i]);
log("Mixer " + (i + 1) + ": " + infos[i]);
try {
mixer.open();
for (Scenario scenario : scenarios) {
testSDL(mixer, scenario);
testTDL(mixer, scenario);
}
mixer.close();
} catch (LineUnavailableException ex) {
log("LineUnavailableException: " + ex);
}
}
if (failed == 0) {
log("PASSED (" + total + " tests)");
} else {
log("FAILED (" + failed + " of " + total + " tests)");
throw new Exception("Test FAILED");
}
}
Aggregations