java applet 输出多行_java – 在Applet中列出输入和输出音频设备

我正在运行一个签名的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值