Search in sources :

Example 1 with Mixer

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

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;
}
Also used : Mixer(javax.sound.sampled.Mixer) ArrayList(java.util.ArrayList)

Example 3 with Mixer

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");
}
Also used : Type(javax.sound.sampled.AudioFileFormat.Type) Mixer(javax.sound.sampled.Mixer)

Example 4 with Mixer

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();
    }
}
Also used : DataLine(javax.sound.sampled.DataLine) SourceDataLine(javax.sound.sampled.SourceDataLine) Mixer(javax.sound.sampled.Mixer) LineUnavailableException(javax.sound.sampled.LineUnavailableException) URL(java.net.URL) AudioInputStream(javax.sound.sampled.AudioInputStream) SourceDataLine(javax.sound.sampled.SourceDataLine) AudioFormat(javax.sound.sampled.AudioFormat)

Example 5 with Mixer

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

Aggregations

Mixer (javax.sound.sampled.Mixer)10 LineUnavailableException (javax.sound.sampled.LineUnavailableException)6 DataLine (javax.sound.sampled.DataLine)5 AudioFormat (javax.sound.sampled.AudioFormat)4 SourceDataLine (javax.sound.sampled.SourceDataLine)3 IOException (java.io.IOException)2 Type (javax.sound.sampled.AudioFileFormat.Type)2 AudioInputStream (javax.sound.sampled.AudioInputStream)2 Line (javax.sound.sampled.Line)2 Port (javax.sound.sampled.Port)2 URL (java.net.URL)1 ShortBuffer (java.nio.ShortBuffer)1 ArrayList (java.util.ArrayList)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 FloatControl (javax.sound.sampled.FloatControl)1 Info (javax.sound.sampled.Line.Info)1 TargetDataLine (javax.sound.sampled.TargetDataLine)1 CanvasFrame (org.bytedeco.javacv.CanvasFrame)1 FFmpegFrameRecorder (org.bytedeco.javacv.FFmpegFrameRecorder)1 Frame (org.bytedeco.javacv.Frame)1