下面列出了javax.sound.sampled.Line.Info#javax.sound.sampled.Line 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Returns the first complete Line.Info object it finds that
* matches the one specified, or null if no matching Line.Info
* object is found.
*/
final Line.Info getLineInfo(Line.Info info) {
if (info == null) {
return null;
}
// $$kk: 05.31.99: need to change this so that
// the format and buffer size get set in the
// returned info object for data lines??
for (int i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
return sourceLineInfo[i];
}
}
for (int i = 0; i < targetLineInfo.length; i++) {
if (info.matches(targetLineInfo[i])) {
return targetLineInfo[i];
}
}
return null;
}
public final Line.Info[] getTargetLineInfo(Line.Info info) {
int i;
Vector vec = new Vector();
for (i = 0; i < targetLineInfo.length; i++) {
if (info.matches(targetLineInfo[i])) {
vec.addElement(targetLineInfo[i]);
}
}
Line.Info[] returnedArray = new Line.Info[vec.size()];
for (i = 0; i < returnedArray.length; i++) {
returnedArray[i] = (Line.Info)vec.elementAt(i);
}
return returnedArray;
}
/**
* Close all lines and then close this mixer.
*/
public final synchronized void close() {
if (Printer.trace) Printer.trace(">> AbstractMixer: close()");
if (isOpen()) {
// close all source lines
Line[] localLines = getSourceLines();
for (int i = 0; i<localLines.length; i++) {
localLines[i].close();
}
// close all target lines
localLines = getTargetLines();
for (int i = 0; i<localLines.length; i++) {
localLines[i].close();
}
implClose();
// set the open state to false and send events
setOpen(false);
}
manuallyOpened = false;
if (Printer.trace) Printer.trace("<< AbstractMixer: close() succeeded");
}
/**
* Removes this line from the list of open source lines and
* open target lines, if it exists in either.
* If the list is now empty, closes the mixer.
*/
final synchronized void close(Line line) {
if (Printer.trace) Printer.trace(">> AbstractMixer: close(" + line + ")");
// $$kk: 06.11.99: ignore ourselves for now
if (this.equals(line)) {
if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") nothing done");
return;
}
sourceLines.removeElement(line);
targetLines.removeElement(line);
if (Printer.debug) Printer.debug("AbstractMixer: close(line): sourceLines.size() now: " + sourceLines.size());
if (Printer.debug) Printer.debug("AbstractMixer: close(line): targetLines.size() now: " + targetLines.size());
if (sourceLines.isEmpty() && targetLines.isEmpty() && !manuallyOpened) {
if (Printer.trace) Printer.trace("AbstractMixer: close(" + line + "): need to close the mixer");
close();
}
if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") succeeded");
}
/**
* Returns the first complete Line.Info object it finds that
* matches the one specified, or null if no matching Line.Info
* object is found.
*/
final Line.Info getLineInfo(Line.Info info) {
if (info == null) {
return null;
}
// $$kk: 05.31.99: need to change this so that
// the format and buffer size get set in the
// returned info object for data lines??
for (int i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
return sourceLineInfo[i];
}
}
for (int i = 0; i < targetLineInfo.length; i++) {
if (info.matches(targetLineInfo[i])) {
return targetLineInfo[i];
}
}
return null;
}
/**
* Starts the mixer.
*/
final synchronized void start(Line line) {
if (Printer.trace) Printer.trace(">> AbstractMixer: start(" + line + ")");
// $$kk: 06.11.99: ignore ourselves for now
if (this.equals(line)) {
if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") nothing done");
return;
}
// we just start the mixer regardless of anything else here.
if (!started) {
if (Printer.debug) Printer.debug("AbstractMixer: start(line): starting the mixer");
implStart();
started = true;
}
if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") succeeded");
}
public final boolean isLineSupported(Line.Info info) {
int i;
for (i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
return true;
}
}
for (i = 0; i < targetLineInfo.length; i++) {
if (info.matches(targetLineInfo[i])) {
return true;
}
}
return false;
}
public final Line.Info[] getTargetLineInfo(Line.Info info) {
int i;
Vector vec = new Vector();
for (i = 0; i < targetLineInfo.length; i++) {
if (info.matches(targetLineInfo[i])) {
vec.addElement(targetLineInfo[i]);
}
}
Line.Info[] returnedArray = new Line.Info[vec.size()];
for (i = 0; i < returnedArray.length; i++) {
returnedArray[i] = (Line.Info)vec.elementAt(i);
}
return returnedArray;
}
@Override
public Line[] getSourceLines() {
Line[] localLines;
synchronized (control_mutex) {
if (mainmixer == null)
return new Line[0];
SoftMixingDataLine[] sourceLines = mainmixer.getOpenLines();
localLines = new Line[sourceLines.length];
for (int i = 0; i < localLines.length; i++) {
localLines[i] = sourceLines[i];
}
}
return localLines;
}
/**
* Close all lines and then close this mixer.
*/
@Override
public final synchronized void close() {
if (Printer.trace) Printer.trace(">> AbstractMixer: close()");
if (isOpen()) {
// close all source lines
Line[] localLines = getSourceLines();
for (int i = 0; i<localLines.length; i++) {
localLines[i].close();
}
// close all target lines
localLines = getTargetLines();
for (int i = 0; i<localLines.length; i++) {
localLines[i].close();
}
implClose();
// set the open state to false and send events
setOpen(false);
}
manuallyOpened = false;
if (Printer.trace) Printer.trace("<< AbstractMixer: close() succeeded");
}
public final Line.Info[] getSourceLineInfo(Line.Info info) {
int i;
Vector vec = new Vector();
for (i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
vec.addElement(sourceLineInfo[i]);
}
}
Line.Info[] returnedArray = new Line.Info[vec.size()];
for (i = 0; i < returnedArray.length; i++) {
returnedArray[i] = (Line.Info)vec.elementAt(i);
}
return returnedArray;
}
/**
* Build device info and determine default devices.
*/
private void sniffAvailableMixers() {
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
for (int i = 0; i < mixers.length; i++) {
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.name = mixers[i].getName();
Mixer mixer = AudioSystem.getMixer(mixers[i]);
Line.Info[] lines = mixer.getTargetLineInfo();
deviceInfo.maxInputs = scanMaxChannels(lines);
// Remember first device that supports input.
if ((defaultInputDeviceID < 0) && (deviceInfo.maxInputs > 0)) {
defaultInputDeviceID = i;
}
lines = mixer.getSourceLineInfo();
deviceInfo.maxOutputs = scanMaxChannels(lines);
// Remember first device that supports output.
if ((defaultOutputDeviceID < 0) && (deviceInfo.maxOutputs > 0)) {
defaultOutputDeviceID = i;
}
deviceRecords.add(deviceInfo);
}
}
/**
* Constructs a new AbstractMixer.
* @param mixer the mixer with which this line is associated
* @param controls set of supported controls
*/
protected AbstractMixer(Mixer.Info mixerInfo,
Control[] controls,
Line.Info[] sourceLineInfo,
Line.Info[] targetLineInfo) {
// Line.Info, AbstractMixer, Control[]
super(new Line.Info(Mixer.class), null, controls);
// setup the line part
this.mixer = this;
if (controls == null) {
controls = new Control[0];
}
// setup the mixer part
this.mixerInfo = mixerInfo;
this.sourceLineInfo = sourceLineInfo;
this.targetLineInfo = targetLineInfo;
}
@Override
public int getMaxLines(Line.Info info) {
Line.Info fullInfo = getLineInfo(info);
// if it's not supported at all, return 0.
if (fullInfo == null) {
return 0;
}
if (fullInfo instanceof DataLine.Info) {
// DirectAudioDevices should mix !
return getMaxSimulLines();
}
return 0;
}
/**
* Starts the mixer.
*/
final synchronized void start(Line line) {
if (Printer.trace) Printer.trace(">> AbstractMixer: start(" + line + ")");
// $$kk: 06.11.99: ignore ourselves for now
if (this.equals(line)) {
if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") nothing done");
return;
}
// we just start the mixer regardless of anything else here.
if (!started) {
if (Printer.debug) Printer.debug("AbstractMixer: start(line): starting the mixer");
implStart();
started = true;
}
if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") succeeded");
}
/**
* Returns the first complete Line.Info object it finds that
* matches the one specified, or null if no matching Line.Info
* object is found.
*/
final Line.Info getLineInfo(Line.Info info) {
if (info == null) {
return null;
}
// $$kk: 05.31.99: need to change this so that
// the format and buffer size get set in the
// returned info object for data lines??
for (int i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
return sourceLineInfo[i];
}
}
for (int i = 0; i < targetLineInfo.length; i++) {
if (info.matches(targetLineInfo[i])) {
return targetLineInfo[i];
}
}
return null;
}
/**
* Removes this line from the list of open source lines and
* open target lines, if it exists in either.
* If the list is now empty, closes the mixer.
*/
final synchronized void close(Line line) {
if (Printer.trace) Printer.trace(">> AbstractMixer: close(" + line + ")");
// $$kk: 06.11.99: ignore ourselves for now
if (this.equals(line)) {
if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") nothing done");
return;
}
sourceLines.removeElement(line);
targetLines.removeElement(line);
if (Printer.debug) Printer.debug("AbstractMixer: close(line): sourceLines.size() now: " + sourceLines.size());
if (Printer.debug) Printer.debug("AbstractMixer: close(line): targetLines.size() now: " + targetLines.size());
if (sourceLines.isEmpty() && targetLines.isEmpty() && !manuallyOpened) {
if (Printer.trace) Printer.trace("AbstractMixer: close(" + line + "): need to close the mixer");
close();
}
if (Printer.trace) Printer.trace("<< AbstractMixer: close(" + line + ") succeeded");
}
/**
* Close all lines and then close this mixer.
*/
public final synchronized void close() {
if (Printer.trace) Printer.trace(">> AbstractMixer: close()");
if (isOpen()) {
// close all source lines
Line[] localLines = getSourceLines();
for (int i = 0; i<localLines.length; i++) {
localLines[i].close();
}
// close all target lines
localLines = getTargetLines();
for (int i = 0; i<localLines.length; i++) {
localLines[i].close();
}
implClose();
// set the open state to false and send events
setOpen(false);
}
manuallyOpened = false;
if (Printer.trace) Printer.trace("<< AbstractMixer: close() succeeded");
}
/**
* Starts the mixer.
*/
final synchronized void start(Line line) {
if (Printer.trace) Printer.trace(">> AbstractMixer: start(" + line + ")");
// $$kk: 06.11.99: ignore ourselves for now
if (this.equals(line)) {
if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") nothing done");
return;
}
// we just start the mixer regardless of anything else here.
if (!started) {
if (Printer.debug) Printer.debug("AbstractMixer: start(line): starting the mixer");
implStart();
started = true;
}
if (Printer.trace) Printer.trace("<< AbstractMixer: start(" + line + ") succeeded");
}
/**
* Constructs a new AbstractMixer.
* @param mixer the mixer with which this line is associated
* @param controls set of supported controls
*/
protected AbstractMixer(Mixer.Info mixerInfo,
Control[] controls,
Line.Info[] sourceLineInfo,
Line.Info[] targetLineInfo) {
// Line.Info, AbstractMixer, Control[]
super(new Line.Info(Mixer.class), null, controls);
// setup the line part
this.mixer = this;
if (controls == null) {
controls = new Control[0];
}
// setup the mixer part
this.mixerInfo = mixerInfo;
this.sourceLineInfo = sourceLineInfo;
this.targetLineInfo = targetLineInfo;
}
public boolean isLineSupported(javax.sound.sampled.Line.Info info) {
if (info != null) {
for (int i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
return true;
}
}
}
return false;
}
public int getMaxLines(Line.Info info) {
Line.Info fullInfo = getLineInfo(info);
// if it's not supported at all, return 0.
if (fullInfo == null) {
return 0;
}
if (fullInfo instanceof Port.Info) {
//return AudioSystem.NOT_SPECIFIED; // if several instances of PortMixerPort
return 1;
}
return 0;
}
public Line getLine(Line.Info info) throws LineUnavailableException {
Line.Info fullInfo = getLineInfo(info);
if ((fullInfo != null) && (fullInfo instanceof Port.Info)) {
for (int i = 0; i < portInfos.length; i++) {
if (fullInfo.equals(portInfos[i])) {
return getPort(i);
}
}
}
throw new IllegalArgumentException("Line unsupported: " + info);
}
public static void test(Line line) {
for (int format = 0; format < formats.length; format++) {
try {
println(" Opening the line with format "+(format+1));
if (line instanceof Clip) {
((Clip) line).open(formats[format], audioData, 0, audioData.length);
} else
if (line instanceof SourceDataLine) {
((SourceDataLine) line).open(formats[format]);
} else
if (line instanceof TargetDataLine) {
((TargetDataLine) line).open(formats[format]);
} else {
println(" Unknown type of line: "+line.getClass());
return;
}
println(" No exception! not OK.");
failed = true;
} catch (IllegalArgumentException iae) {
println(" IllegalArgumentException: "+iae.getMessage());
println(" OK");
} catch (LineUnavailableException lue) {
println(" LineUnavailableException: "+lue.getMessage());
println(" Probably incorrect, but may happen if the test system is correctly set up.");
} catch (Exception e) {
println(" Unexpected Exception: "+e.toString());
println(" NOT OK!");
failed = true;
}
println(" Closing line.");
line.close();
}
}
public int getMaxLines(Line.Info info) {
if (info.getLineClass() == SourceDataLine.class)
return AudioSystem.NOT_SPECIFIED;
if (info.getLineClass() == Clip.class)
return AudioSystem.NOT_SPECIFIED;
return 0;
}
private int scanMaxChannels(Line.Info[] lines) {
int maxChannels = 0;
for (Line.Info line : lines) {
if (line instanceof DataLine.Info) {
int numChannels = scanMaxChannels(((DataLine.Info) line));
if (numChannels > maxChannels) {
maxChannels = numChannels;
}
}
}
return maxChannels;
}
@Override
public javax.sound.sampled.Line.Info[] getSourceLineInfo(
javax.sound.sampled.Line.Info info) {
int i;
ArrayList<javax.sound.sampled.Line.Info> infos = new ArrayList<>();
for (i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
infos.add(sourceLineInfo[i]);
}
}
return infos.toArray(new Line.Info[infos.size()]);
}
/**
* Determines whether this is a source line for this mixer.
* Right now this just checks whether it's supported, but should
* check whether it actually belongs to this mixer....
*/
final boolean isSourceLine(Line.Info info) {
for (int i = 0; i < sourceLineInfo.length; i++) {
if (info.matches(sourceLineInfo[i])) {
return true;
}
}
return false;
}
/**
* Determines whether this is a target line for this mixer.
* Right now this just checks whether it's supported, but should
* check whether it actually belongs to this mixer....
*/
final boolean isTargetLine(Line.Info info) {
for (int i = 0; i < targetLineInfo.length; i++) {
if (info.matches(targetLineInfo[i])) {
return true;
}
}
return false;
}
public Line getLine(Line.Info info) throws LineUnavailableException {
if (!isLineSupported(info))
throw new IllegalArgumentException("Line unsupported: " + info);
if ((info.getLineClass() == SourceDataLine.class)) {
return new SoftMixingSourceDataLine(this, (DataLine.Info) info);
}
if ((info.getLineClass() == Clip.class)) {
return new SoftMixingClip(this, (DataLine.Info) info);
}
throw new IllegalArgumentException("Line unsupported: " + info);
}