下面列出了javax.sound.sampled.Mixer#Info ( ) 实例代码,或者点击链接到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.Info[] getMixerInfo() {
synchronized (PortMixerProvider.class) {
Mixer.Info[] localArray = new Mixer.Info[infos.length];
System.arraycopy(infos, 0, localArray, 0, infos.length);
return localArray;
}
}
public Mixer.Info[] getMixerInfo() {
synchronized (DirectAudioDeviceProvider.class) {
Mixer.Info[] localArray = new Mixer.Info[infos.length];
System.arraycopy(infos, 0, localArray, 0, infos.length);
return localArray;
}
}
public Mixer.Info[] getMixerInfo() {
synchronized (PortMixerProvider.class) {
Mixer.Info[] localArray = new Mixer.Info[infos.length];
System.arraycopy(infos, 0, localArray, 0, infos.length);
return localArray;
}
}
public Mixer getMixer(Mixer.Info info) {
synchronized (PortMixerProvider.class) {
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 (PortMixerProvider.class) {
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));
}
public Mixer getMixer(final String name) {
Mixer mixer = null;
if (name != null) {
final Mixer.Info[] mInfos = AudioSystem.getMixerInfo();
if (mInfos != null) {
for (final Info mInfo : mInfos) {
if (mInfo.getName().equals(name)) {
mixer = AudioSystem.getMixer(mInfo);
break;
}
}
}
}
return mixer;
}
Line getDataLine(DataLine.Info info) throws LineUnavailableException {
Line dataLine;
if (deviceID >= 0) {
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
Mixer mixer = AudioSystem.getMixer(mixers[deviceID]);
dataLine = mixer.getLine(info);
} else {
dataLine = AudioSystem.getLine(info);
}
return dataLine;
}
public Mixer.Info[] getMixerInfo() {
synchronized (PortMixerProvider.class) {
Mixer.Info[] localArray = new Mixer.Info[infos.length];
System.arraycopy(infos, 0, localArray, 0, infos.length);
return localArray;
}
}
public final Mixer.Info getMixerInfo() {
return mixerInfo;
}
public static void main(String[] args) throws Exception {
println("This is an interactive test for DirectAudio.");
println("If the tone repeats, the test is failed.");
println("");
println("Make sure that you have speakers connected");
println("and that the system mixer is not muted.");
println("");
println("Press a key to start the test.");
key();
Mixer.Info[] mixers=null;
println(" ...using self-generated sine wave for playback");
audioFormat = new AudioFormat((float)sampleRate, 8, 1, true, true);
for (int i=0; i<audioData.length; i++) {
audioData[i] = (byte)(Math.sin(RAD*frequency/sampleRate*i)*127.0);
}
info = new DataLine.Info(SourceDataLine.class, audioFormat);
mixers = AudioSystem.getMixerInfo();
int succMixers = 0;
for (int i=0; i<mixers.length; i++) {
println(""+mixers[i]+":");
if ((mixers[i].getName()+mixers[i].getDescription()+mixers[i].getVendor()).indexOf("Direct") < 0) {
println(" ->not a DirectAudio Mixer!");
} else {
try {
Mixer mixer = AudioSystem.getMixer(mixers[i]);
if (!mixer.isLineSupported(info)) {
println(" ->doesn't support SourceDataLine!");
} else {
succMixers++;
println(" -> is getting tested.");
play(mixer);
}
} catch (Exception e) {
println(" -> Exception occured: "+e);
e.printStackTrace();
}
}
}
if (succMixers == 0) {
println("No DirectAudio mixers available! ");
println("Cannot run test.");
}
}
public final Mixer.Info getMixerInfo() {
return mixerInfo;
}
public static void main(String args[]) throws Exception {
int SDLformats = 0;
int TDLformats = 0;
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
for(int i=0; i<mixerInfo.length; i++){
Mixer.Info thisMixerInfo = mixerInfo[i];
System.out.println("Mixer #"+i+": "
+ thisMixerInfo.getName()
+ ": " + thisMixerInfo.getDescription());
Mixer mixer = AudioSystem.getMixer(thisMixerInfo);
Line.Info[] srcLineInfo = mixer.getSourceLineInfo();
Line.Info[] dstLineInfo = mixer.getTargetLineInfo();
int count = srcLineInfo.length + dstLineInfo.length;
System.out.print(" -> " + (srcLineInfo.length + dstLineInfo.length) + " line");
switch (count) {
case 0: System.out.println("s"); break;
case 1: System.out.println(""); break;
default: System.out.println("s:"); break;
}
int l;
for (l = 0; l < srcLineInfo.length; l++) {
System.out.println(" "+srcLineInfo[l].toString());
if (srcLineInfo[l].getLineClass() == SourceDataLine.class
&& (srcLineInfo[l] instanceof DataLine.Info)) {
SDLformats += ((DataLine.Info) srcLineInfo[l]).getFormats().length;
}
}
for (l = 0; l < dstLineInfo.length; l++) {
System.out.println(" "+dstLineInfo[l].toString());
if (dstLineInfo[l].getLineClass() == TargetDataLine.class
&& (dstLineInfo[l] instanceof DataLine.Info)) {
TDLformats += ((DataLine.Info) dstLineInfo[l]).getFormats().length;
}
}
}
if (mixerInfo.length == 0) {
System.out.println("[no mixers present]");
}
System.out.println(""+SDLformats+" total formats for SourceDataLines");
System.out.println(""+TDLformats+" total formats for TargetDataLines");
System.out.println("");
System.out.println("If there are audio devices correctly installed on your");
System.out.println("system, you should see at least one Mixer, and in total");
System.out.println("at least each one SourceDataLine and TargetDataLine, both");
System.out.println("providing at least one format.");
System.out.println("");
System.out.println("Now disable your soundcard and repeat the test.");
System.out.println("The corresponding mixer(s) should not provide any formats");
System.out.println("anymore. If you disable all available soundcards");
System.out.println("on your computer, the number of formats above should be");
System.out.println("0 for both line types (although mixers are allowed to exist).");
}
/**
* Indicates whether the mixer provider supports the mixer represented by
* the specified mixer info object.
* <p>
* The full set of mixer info objects that represent the mixers supported
* by this {@code MixerProvider} may be obtained
* through the {@code getMixerInfo} method.
*
* @param info an info object that describes the mixer for which support is queried
* @return {@code true} if the specified mixer is supported,
* otherwise {@code false}
* @see #getMixerInfo()
*/
public boolean isMixerSupported(Mixer.Info info) {
Mixer.Info infos[] = getMixerInfo();
for(int i=0; i<infos.length; i++){
if( info.equals( infos[i] ) ) {
return true;
}
}
return false;
}
/**
* Indicates whether the mixer provider supports the mixer represented by
* the specified mixer info object.
* <p>
* The full set of mixer info objects that represent the mixers supported
* by this {@code MixerProvider} may be obtained
* through the {@code getMixerInfo} method.
*
* @param info an info object that describes the mixer for which support is queried
* @return {@code true} if the specified mixer is supported,
* otherwise {@code false}
* @see #getMixerInfo()
*/
public boolean isMixerSupported(Mixer.Info info) {
Mixer.Info infos[] = getMixerInfo();
for(int i=0; i<infos.length; i++){
if( info.equals( infos[i] ) ) {
return true;
}
}
return false;
}
/**
* Obtains the set of info objects representing the mixer
* or mixers provided by this MixerProvider.
* <p>
* The {@code isMixerSupported} method returns {@code true}
* for all the info objects returned by this method.
* The corresponding mixer instances for the info objects
* are returned by the {@code getMixer} method.
*
* @return a set of mixer info objects
* @see #getMixer(javax.sound.sampled.Mixer.Info) getMixer(Mixer.Info)
* @see #isMixerSupported(javax.sound.sampled.Mixer.Info) isMixerSupported(Mixer.Info)
*/
public abstract Mixer.Info[] getMixerInfo();
/**
* Obtains the set of info objects representing the mixer
* or mixers provided by this MixerProvider.
* <p>
* The {@code isMixerSupported} method returns {@code true}
* for all the info objects returned by this method.
* The corresponding mixer instances for the info objects
* are returned by the {@code getMixer} method.
*
* @return a set of mixer info objects
* @see #getMixer(javax.sound.sampled.Mixer.Info) getMixer(Mixer.Info)
* @see #isMixerSupported(javax.sound.sampled.Mixer.Info) isMixerSupported(Mixer.Info)
*/
public abstract Mixer.Info[] getMixerInfo();
/**
* Obtains the set of info objects representing the mixer or mixers provided
* by this MixerProvider.
* <p>
* The {@code isMixerSupported} method returns {@code true} for all the info
* objects returned by this method. The corresponding mixer instances for
* the info objects are returned by the {@code getMixer} method.
*
* @return a set of mixer info objects
* @see #getMixer(Mixer.Info)
* @see #isMixerSupported(Mixer.Info)
*/
public abstract Mixer.Info[] getMixerInfo();
/**
* Obtains an instance of the mixer represented by the info object.
* <p>
* The full set of the mixer info objects that represent the mixers
* supported by this {@code MixerProvider} may be obtained
* through the {@code getMixerInfo} method.
* Use the {@code isMixerSupported} method to test whether
* this {@code MixerProvider} supports a particular mixer.
*
* @param info an info object that describes the desired mixer
* @return mixer instance
* @throws IllegalArgumentException if the info object specified does not
* match the info object for a mixer supported by this MixerProvider.
* @see #getMixerInfo()
* @see #isMixerSupported(javax.sound.sampled.Mixer.Info) isMixerSupported(Mixer.Info)
*/
public abstract Mixer getMixer(Mixer.Info info);
/**
* Obtains the set of info objects representing the mixer
* or mixers provided by this MixerProvider.
* <p>
* The {@code isMixerSupported} method returns {@code true}
* for all the info objects returned by this method.
* The corresponding mixer instances for the info objects
* are returned by the {@code getMixer} method.
*
* @return a set of mixer info objects
* @see #getMixer(javax.sound.sampled.Mixer.Info) getMixer(Mixer.Info)
* @see #isMixerSupported(javax.sound.sampled.Mixer.Info) isMixerSupported(Mixer.Info)
*/
public abstract Mixer.Info[] getMixerInfo();