下面列出了javax.sound.sampled.Mixer#getSourceLineInfo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
@Override
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException(
String.format("Mixer %s not supported by this provider", info));
}
@Override
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException(
String.format("Mixer %s not supported by this provider", info));
}
private Line.Info[] getPortInfo(Mixer mixer) {
Line.Info[] infos;
List<Line.Info> portInfoList = new ArrayList<Line.Info>();
infos = mixer.getSourceLineInfo();
for (Line.Info info : infos) {
if (info instanceof Port.Info || info instanceof DataLine.Info) {
portInfoList.add((Line.Info) info);
}
}
infos = mixer.getTargetLineInfo();
for (Line.Info info1 : infos) {
if (info1 instanceof Port.Info || info1 instanceof DataLine.Info) {
portInfoList.add((Line.Info) info1);
}
}
return portInfoList.toArray(EMPTY_PORT_INFO_ARRAY);
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
public Mixer getMixer(Mixer.Info info) {
synchronized (DirectAudioDeviceProvider.class) {
// if the default device is asked, we provide the mixer
// with SourceDataLine's
if (info == null) {
for (int i = 0; i < infos.length; i++) {
Mixer mixer = getDevice(infos[i]);
if (mixer.getSourceLineInfo().length > 0) {
return mixer;
}
}
}
// otherwise get the first mixer that matches
// the requested info object
for (int i = 0; i < infos.length; i++) {
if (infos[i].equals(info)) {
return getDevice(infos[i]);
}
}
}
throw new IllegalArgumentException("Mixer " + info.toString() + " not supported by this provider.");
}
/**
* 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);
}
}
/**
* 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);
}
}
public static void main(String[] args) throws Exception {
boolean res=true;
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
for (int i = 0; i < mixerInfo.length; i++) {
Mixer mixer = AudioSystem.getMixer(mixerInfo[i]);
System.out.println(mixer);
Line.Info[] lineinfo = mixer.getSourceLineInfo();
for (int j = 0; j < lineinfo.length; j++) {
System.out.println(" " + lineinfo[j]);
try {
AudioFormat[] formats = ((DataLine.Info)lineinfo[j]).getFormats();
for (int k = 0; k < formats.length; k++) {
if ( (formats[k].getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
|| formats[k].getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED))
&& (formats[k].getFrameSize() != AudioSystem.NOT_SPECIFIED)
&& ((formats[k].getSampleSizeInBits() == 16) || (formats[k].getSampleSizeInBits() == 8))
&& ((((formats[k].getSampleSizeInBits() + 7) / 8) * formats[k].getChannels()) != formats[k].getFrameSize())) {
System.out.println(" # " + formats[k] + ", getFrameSize() wrongly returns"+ formats[k].getFrameSize());
res=false;
}
}
} catch (ClassCastException e) {
}
}
}
if (res) {
System.out.println("Test passed");
} else {
System.out.println("Test failed");
throw new Exception("Test failed");
}
}
private static boolean testMixer(Mixer mixer, Class lineType,
String providerClassName,
String instanceName) {
boolean allOk = true;
try {
String propertyValue = (providerClassName != null) ? providerClassName: "" ;
propertyValue += "#" + instanceName;
out("property value: " + propertyValue);
System.setProperty(lineType.getName(), propertyValue);
Line line = null;
Line.Info info = null;
Line.Info[] infos;
AudioFormat format = null;
if (lineType == SourceDataLine.class || lineType == Clip.class) {
infos = mixer.getSourceLineInfo();
format = getFirstLinearFormat(infos);
info = new DataLine.Info(lineType, format);
} else if (lineType == TargetDataLine.class) {
infos = mixer.getTargetLineInfo();
format = getFirstLinearFormat(infos);
info = new DataLine.Info(lineType, format);
} else if (lineType == Port.class) {
/* Actually, a Ports Mixer commonly has source infos
as well as target infos. We ignore this here, since we
just need a random one. */
infos = mixer.getSourceLineInfo();
for (int i = 0; i < infos.length; i++) {
if (infos[i] instanceof Port.Info) {
info = infos[i];
break;
}
}
}
out("Line.Info: " + info);
line = AudioSystem.getLine(info);
out("line: " + line);
if (! lineType.isInstance(line)) {
out("type " + lineType + " failed: class should be '" +
lineType + "' but is '" + line.getClass() + "'!");
allOk = false;
}
} catch (Exception e) {
out("Exception thrown; Test NOT failed.");
e.printStackTrace();
}
return allOk;
}
public static void printAudioInfo() {
P.out("----------------- printAudioInfo -------------------");
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
for(int i = 0; i < mixerInfo.length; i++) {
P.out("########## mixerInfo["+i+"]", mixerInfo[i].getName());
// Mixer mixer = AudioSystem.getMixer(null); // default mixer
Mixer mixer = AudioSystem.getMixer(mixerInfo[i]); // default mixer
try {
mixer.open();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
P.out("Supported SourceDataLines of default mixer (%s):\n\n", mixer.getMixerInfo().getName());
for(Line.Info info : mixer.getSourceLineInfo()) {
if(SourceDataLine.class.isAssignableFrom(info.getLineClass())) {
SourceDataLine.Info info2 = (SourceDataLine.Info) info;
P.out(info2);
System.out.printf(" max buffer size: \t%d\n", info2.getMaxBufferSize());
System.out.printf(" min buffer size: \t%d\n", info2.getMinBufferSize());
AudioFormat[] formats = info2.getFormats();
P.out(" Supported Audio formats: ");
for(AudioFormat format : formats) {
P.out(" "+format);
System.out.printf(" encoding: %s\n", format.getEncoding());
System.out.printf(" channels: %d\n", format.getChannels());
System.out.printf(format.getFrameRate()==-1?"":" frame rate [1/s]: %s\n", format.getFrameRate());
System.out.printf(" frame size [bytes]: %d\n", format.getFrameSize());
System.out.printf(format.getSampleRate()==-1?"":" sample rate [1/s]: %s\n", format.getSampleRate());
System.out.printf(" sample size [bit]: %d\n", format.getSampleSizeInBits());
System.out.printf(" big endian: %b\n", format.isBigEndian());
Map<String,Object> prop = format.properties();
if(!prop.isEmpty()) {
P.out(" Properties: ");
for(Map.Entry<String, Object> entry : prop.entrySet()) {
System.out.printf(" %s: \t%s\n", entry.getKey(), entry.getValue());
}
}
}
P.out();
} else {
P.out(info.toString());
}
P.out();
}
mixer.close();
}
}