javax.sound.sampled.AudioSystem#getMixerInfo ( )源码实例Demo

下面列出了javax.sound.sampled.AudioSystem#getMixerInfo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public static void main(String[] args) throws Exception {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    log("" + infos.length + " mixers detected");
    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        log("Mixer " + (i+1) + ": " + infos[i]);
        try {
            mixer.open();
            for (Scenario scenario: scenarios) {
                testSDL(mixer, scenario);
                testTDL(mixer, scenario);
            }
            mixer.close();
        } catch (LineUnavailableException ex) {
            log("LineUnavailableException: " + ex);
        }
    }
    if (failed == 0) {
        log("PASSED (" + total + " tests)");
    } else {
        log("FAILED (" + failed + " of " + total + " tests)");
        throw new Exception("Test FAILED");
    }
}
 
源代码2 项目: openjdk-jdk9   文件: DataLineInfoNegBufferSize.java
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
源代码3 项目: openjdk-jdk9   文件: SDLLinuxCrash.java
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
public static void main(String[] args) throws Exception {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    log("" + infos.length + " mixers detected");
    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        log("Mixer " + (i+1) + ": " + infos[i]);
        try {
            mixer.open();
            for (Scenario scenario: scenarios) {
                testSDL(mixer, scenario);
                testTDL(mixer, scenario);
            }
            mixer.close();
        } catch (LineUnavailableException ex) {
            log("LineUnavailableException: " + ex);
        }
    }
    if (failed == 0) {
        log("PASSED (" + total + " tests)");
    } else {
        log("FAILED (" + failed + " of " + total + " tests)");
        throw new Exception("Test FAILED");
    }
}
 
public static void main(String[] args) throws Exception {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    log("" + infos.length + " mixers detected");
    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        log("Mixer " + (i+1) + ": " + infos[i]);
        try {
            mixer.open();
            for (Scenario scenario: scenarios) {
                testSDL(mixer, scenario);
                testTDL(mixer, scenario);
            }
            mixer.close();
        } catch (LineUnavailableException ex) {
            log("LineUnavailableException: " + ex);
        }
    }
    if (failed == 0) {
        log("PASSED (" + total + " tests)");
    } else {
        log("FAILED (" + failed + " of " + total + " tests)");
        throw new Exception("Test FAILED");
    }
}
 
源代码6 项目: jsyn   文件: JavaSoundAudioDevice.java
/**
 * 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);
    }
}
 
源代码7 项目: openjdk-jdk9   文件: ClipSetEndPoint.java
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: " + e);
    }
    if (!result) {
        System.err.println(
                "Soundcard does not exist or sound drivers not installed!");
        System.err.println(
                "This test requires sound drivers for execution.");
    }
    return result;
}
 
public static void main(String[] args) throws Exception {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    log("" + infos.length + " mixers detected");
    for (int i=0; i<infos.length; i++) {
        Mixer mixer = AudioSystem.getMixer(infos[i]);
        log("Mixer " + (i+1) + ": " + infos[i]);
        try {
            mixer.open();
            for (Scenario scenario: scenarios) {
                testSDL(mixer, scenario);
                testTDL(mixer, scenario);
            }
            mixer.close();
        } catch (LineUnavailableException ex) {
            log("LineUnavailableException: " + ex);
        }
    }
    if (failed == 0) {
        log("PASSED (" + total + " tests)");
    } else {
        log("FAILED (" + failed + " of " + total + " tests)");
        throw new Exception("Test FAILED");
    }
}
 
源代码9 项目: openjdk-jdk9   文件: ClipCloseLoss.java
public static void main(String[] args) throws Exception    {
    if (isSoundcardInstalled()) {
        bais.mark(0);
        run(null);
        Mixer.Info[] infos = AudioSystem.getMixerInfo();
        for (int i = 0; i<infos.length; i++) {
            try {
                Mixer m = AudioSystem.getMixer(infos[i]);
                run(m);
            } catch (Exception e) {
            }
        }
        out("Waiting 1 second to dispose of all threads");
        Thread.sleep(1000);
        if (getClipThreadCount() > 0) {
            out("Unused clip threads exist! Causes test failure");
            failed = true;
        }
        if (failed) throw new Exception("Test FAILED!");
        if (success > 0) {
            out("Test passed.");
        } else {
            System.err.println("Test could not execute: please install an audio device");
        }
    }
}
 
源代码10 项目: openjdk-jdk9   文件: ClipDrain.java
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
源代码11 项目: openjdk-jdk9   文件: BufferSizeCheck.java
/**
 * Returns true if at least one soundcard is correctly installed
 * on the system.
 */
public static boolean isSoundcardInstalled() {
    boolean result = false;
    try {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        if (mixers.length > 0) {
            result = AudioSystem.getSourceDataLine(null) != null;
        }
    } catch (Exception e) {
        System.err.println("Exception occured: "+e);
    }
    if (!result) {
        System.err.println("Soundcard does not exist or sound drivers not installed!");
        System.err.println("This test requires sound drivers for execution.");
    }
    return result;
}
 
源代码12 项目: stendhal   文件: DeviceEvaluator.java
public DeviceEvaluator()
{
	Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();

	mDevices = new ArrayList<Device>(mixerInfos.length);

	for(Mixer.Info info: mixerInfos) {
		mDevices.add(new Device(info.getName(), info.getDescription(), AudioSystem.getMixer(info)));
	}
}
 
源代码13 项目: gama   文件: BasicPlayer.java
public List<String> getMixers() {
	final ArrayList<String> mixers = new ArrayList<>();
	final Mixer.Info[] mInfos = AudioSystem.getMixerInfo();
	if (mInfos != null) {
		for (final Info mInfo : mInfos) {
			final Line.Info lineInfo = new Line.Info(SourceDataLine.class);
			final Mixer mixer = AudioSystem.getMixer(mInfo);
			if (mixer.isLineSupported(lineInfo)) {
				mixers.add(mInfo.getName());
			}
		}
	}
	return mixers;
}
 
源代码14 项目: MyBox   文件: MediaTools.java
public static void audioSystem() {
    Mixer.Info[] infos = AudioSystem.getMixerInfo();
    for (Mixer.Info info : infos) {
        logger.debug(info.getName() + " " + info.getVendor() + " " + info.getVersion() + " " + info.getDescription());
    }
    AudioFileFormat.Type[] formats = AudioSystem.getAudioFileTypes();
    logger.debug(Arrays.asList(formats));
}
 
源代码15 项目: openjdk-jdk9   文件: Has16and32KHz.java
public static void main(String[] args) throws Exception {
    boolean res=true;

    Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
    System.out.println(mixerInfo.length+" mixers on system.");
    if (mixerInfo.length == 0) {
        System.out.println("Cannot execute test. Not Failed!");
    } else {
        for (int i = 0; i < mixerInfo.length; i++) {
            Mixer mixer = AudioSystem.getMixer(mixerInfo[i]);
            System.out.println();
            System.out.println(mixer+":");
            showMixerLines(mixer.getSourceLineInfo());
            showMixerLines(mixer.getTargetLineInfo());


        }
        res=ok16 && ok32;
    }
    if (res) {
        System.out.println("Test passed");
    } else {
        System.out.println("Test failed");
        throw new Exception("Test failed");
    }
    //ystem.exit(res?0:1);
}
 
源代码16 项目: openjdk-jdk9   文件: ChangingBuffer.java
private static void doAll(boolean bigEndian) throws Exception {
    AudioFormat pcm = new AudioFormat(
                        AudioFormat.Encoding.PCM_SIGNED,
                        samplerate, 16, 1, 2, samplerate, bigEndian);
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        for (int i=0; i<mixers.length; i++) {
            Mixer mixer = AudioSystem.getMixer(mixers[i]);
            makeBuffer(); if (doMixerClip(mixer, pcm)) checkBufferClip();
            makeBuffer(); if (doMixerSDL(mixer, pcm)) checkBufferSDL();
        }
        if (mixers.length==0) {
            System.out.println("No mixers available!");
        }

}
 
源代码17 项目: openjdk-jdk9   文件: BogusMixers.java
public static void main(String[] args) throws Exception {
    try {
        out("4667064: Java Sound provides bogus SourceDataLine and TargetDataLine");

        Mixer.Info[]    aInfos = AudioSystem.getMixerInfo();
        out("  available Mixers:");
        for (int i = 0; i < aInfos.length; i++) {
            if (aInfos[i].getName().startsWith("Java Sound Audio Engine")) {
                Mixer mixer = AudioSystem.getMixer(aInfos[i]);
                Line.Info[] tlInfos = mixer.getTargetLineInfo();
                for (int ii = 0; ii<tlInfos.length; ii++) {
                    if (tlInfos[ii].getLineClass() == DataLine.class) {
                        throw new Exception("Bogus TargetDataLine with DataLine info present!");
                    }
                }
            }
            if (aInfos[i].getName().startsWith("WinOS,waveOut,multi threaded")) {
                throw new Exception("Bogus mixer 'WinOS,waveOut,multi threaded' present!");
            }
            out(aInfos[i].getName());
        }
        if (aInfos.length == 0)
        {
            out("[No mixers available] - not a failure of this test case.");
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    out("Test passed");
}
 
protected void printAllMixerNames() {
    for(Mixer.Info info : AudioSystem.getMixerInfo()) {
        P.out(info.getName(), " - ", info.getDescription());
		Mixer m = AudioSystem.getMixer(info);
		mixers.add(m);
		UI.addButton(info.getName(), false);
    }
}
 
源代码19 项目: haxademic   文件: JavaInfo.java
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();
		}
	}
 
源代码20 项目: openjdk-jdk9   文件: PhantomMixers.java
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).");
}