我正在运行一个签名的applet,它需要为用户提供选择输入和输出音频设备的能力(类似于skype提供的).
我从其他thread借用了以下代码:
import javax.sound.sampled.*;
public class SoundAudit {
public static void main(String[] args) { try {
System.out.println("OS: "+System.getProperty("os.name")+" "+
System.getProperty("os.version")+"/"+
System.getProperty("os.arch")+"\nJava: "+
System.getProperty("java.version")+" ("+
System.getProperty("java.vendor")+")\n");
for (Mixer.Info thisMixerInfo : AudioSystem.getMixerInfo()) {
System.out.println("Mixer: "+thisMixerInfo.getDescription()+
" ["+thisMixerInfo.getName()+"]");
Mixer thisMixer = AudioSystem.getMixer(thisMixerInfo);
for (Line.Info thisLineInfo:thisMixer.getSourceLineInfo()) {
if (thisLineInfo.getLineClass().getName().equals(
"javax.sound.sampled.Port")) {
Line thisLine = thisMixer.getLine(thisLineInfo);
thisLine.open();
System.out.println(" Source Port: "
+thisLineInfo.toString());
for (Control thisControl : thisLine.getControls()) {
System.out.println(AnalyzeControl(thisControl));}
thisLine.close();}}
for (Line.Info thisLineInfo:thisMixer.getTargetLineInfo()) {
if (thisLineInfo.getLineClass().getName().equals(
"javax.sound.sampled.Port")) {
Line thisLine = thisMixer.getLine(thisLineInfo);
thisLine.open();
System.out.println(" Target Port: "
+thisLineInfo.toString());
for (Control thisControl : thisLine.getControls()) {
System.out.println(AnalyzeControl(thisControl));}
thisLine.close();}}}
} catch (Exception e) {e.printStackTrace();}}
public static String AnalyzeControl(Control thisControl) {
String type = thisControl.getType().toString();
if (thisControl instanceof BooleanControl) {
return " Control: "+type+" (boolean)"; }
if (thisControl instanceof CompoundControl) {
System.out.println(" Control: "+type+
" (compound - values below)");
String toReturn = "";
for (Control children:
((CompoundControl)thisControl).getMemberControls()) {
toReturn+=" "+AnalyzeControl(children)+"\n";}
return toReturn.substring(0, toReturn.length()-1);}
if (thisControl instanceof EnumControl) {
return " Control:"+type+" (enum: "+thisControl.toString()+")";}
if (thisControl instanceof FloatControl) {
return " Control: "+type+" (float: from "+
((FloatControl) thisControl).getMinimum()+" to "+
((FloatControl) thisControl).getMaximum()+")";}
return " Control: unknown type";}
}
但是我得到了什么:
Mixer: Software mixer and synthesizer [Java Sound Audio Engine]
Mixer: No details available [Microphone (Pink Front)]
我期待获得我的设备的真实列表(我的偏好面板显示3个输出设备和1个麦克风).我在Mac OS X 10.6.7上运行.
还有其他方法可以从Java获取该信息吗?
解决方法:
多年来,它一直是OS X的Java实现的一个非常不幸的限制,特别是对于该平台的BTW,“Java Sound Audio Engine”是唯一可编程的输出音频线.因此,无论您发送到此行,即从您创建的任何Java应用程序中发送的内容,都将始终路由到已在OS X中设置为默认输出的内容,通常是内置扬声器.所以JSAE只是“默认音频输出”的Java术语.根据我们的理解 – 遗憾的是 – 最新版本仍然如此.
为什么不幸?因为它有效地禁用了甚至不起眼的音频路由.我们每天都在处理这些问题,并要求增加各种复杂性.有解决方法,但通过SoundFlower和HiJack Pro等第三方应用程序.例如www.soundPimp.com.
标签:java,javasound
来源: https://codeday.me/bug/20190613/1235377.html