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

Java examples for javax.sound.sampled:Audio

Description

get Available Lines from Audio Mixer

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 {
    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;//from   w  ww . j  a v  a  2s. com
            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