get Available Audio Mixer Output Lines - Java javax.sound.sampled

Java examples for javax.sound.sampled:Audio

Description

get Available Audio Mixer Output Lines

Demo Code


//package com.java2s;

import java.util.ArrayList;
import java.util.List;

import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;

public class Main {
    public static List<Line> getAvailableOutputLines(Mixer mixer) {
        return getAvailableLines(mixer, mixer.getTargetLineInfo());
    }//ww w  .  ja  va2  s  .c  o  m

    private static List<Line> getAvailableLines(Mixer mixer,
            Line.Info[] lineInfos) {
        List<Line> lines = new ArrayList<Line>(lineInfos.length);
        for (Line.Info lineInfo : lineInfos) {
            Line line;
            line = getLineIfAvailable(mixer, lineInfo);
            if (line != null)
                lines.add(line);
        }
        return lines;
    }

    public static Line getLineIfAvailable(Mixer mixer, Line.Info lineInfo) {
        try {
            return mixer.getLine(lineInfo);
        } catch (LineUnavailableException ex) {
            return null;
        }
    }
}

Related Tutorials