Example usage for javax.sound.sampled Mixer getTargetLineInfo

List of usage examples for javax.sound.sampled Mixer getTargetLineInfo

Introduction

In this page you can find the example usage for javax.sound.sampled Mixer getTargetLineInfo.

Prototype

Line.Info[] getTargetLineInfo(Line.Info info);

Source Link

Document

Obtains information about target lines of a particular type supported by the mixer.

Usage

From source file:com.offbynull.voip.audio.gateways.io.AudioRunnable.java

private Object loadDevices() {
    Map<Integer, LineEntry> newOutputDevices = new HashMap<>();
    Map<Integer, LineEntry> newInputDevices = new HashMap<>();
    List<OutputDevice> respOutputDevices = new LinkedList<>();
    List<InputDevice> respInputDevices = new LinkedList<>();

    Mixer.Info[] mixerInfos;/*w ww. j a  v  a2s  .  c o  m*/
    try {
        mixerInfos = AudioSystem.getMixerInfo();
    } catch (Exception e) {
        LOG.error("Unable to get mixers", e);
        return new ErrorResponse("Unable to get mixers: " + e);
    }

    for (Mixer.Info info : mixerInfos) {
        Mixer mixer;
        try {
            mixer = AudioSystem.getMixer(info);
        } catch (Exception e) {
            LOG.error("Unable to get mixer", e);
            continue;
        }

        Line.Info[] lineInfos;
        Map<Integer, LineEntry> newEntries;

        // out devices
        try {
            lineInfos = mixer.getSourceLineInfo(new Line.Info(SourceDataLine.class));
            newEntries = generateLineEntriesFromJavaSound(mixer, lineInfos);
            newOutputDevices.putAll(newEntries);
            newEntries.entrySet().forEach(x -> {
                Mixer.Info mi = x.getValue().getMixer().getMixerInfo();
                String name = "OUT:" + mi.getName() + "/" + mi.getVersion() + "/" + mi.getVendor() + "/"
                        + mi.getDescription();
                OutputDevice outputDevice = new OutputDevice(x.getKey(), name);
                respOutputDevices.add(outputDevice);
            });
        } catch (LineUnavailableException lue) {
            LOG.error("Unable to get line from mixer", lue);
        }

        // in devices
        try {
            lineInfos = mixer.getTargetLineInfo(new Line.Info(TargetDataLine.class));
            newEntries = generateLineEntriesFromJavaSound(mixer, lineInfos);
            newInputDevices.putAll(newEntries);
            newEntries.entrySet().forEach(x -> {
                Mixer.Info mi = x.getValue().getMixer().getMixerInfo();
                String name = "IN:" + mi.getName() + "/" + mi.getVersion() + "/" + mi.getVendor() + "/"
                        + mi.getDescription();
                InputDevice inputDevice = new InputDevice(x.getKey(), name);
                respInputDevices.add(inputDevice);
            });
        } catch (LineUnavailableException lue) {
            LOG.error("Unable to get line from mixer", lue);
        }
    }

    inputDevices = newInputDevices;
    outputDevices = newOutputDevices;
    return new LoadDevicesResponse(respOutputDevices, respInputDevices);
}