使用Java在Ubuntu中获取音频设备名称 [英] Get audio device name in Ubuntu using Java

查看:332
本文介绍了使用Java在Ubuntu中获取音频设备名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试列出所有与Ubuntu使用的名称相同的音频设备.例如,Ubuntu将扬声器列为内置音频,将耳机列为Logitech USB耳机,但是当我使用javax.sound.sampled列出我的设备时,却无法获得相同的名称.我的代码如下:

I'm trying to list all my audio devices with the same names used by Ubuntu. For example, Ubuntu lists Speakers as a Built-in Audio and Headphones as Logitech USB Headset, but I can't get the same names when I list my devices with javax.sound.sampled. My code follows bellow:

Mixer.Info[] infoMixers = AudioSystem.getMixerInfo();

for (Mixer.Info infoMixer : infoMixers) {
    // Get mixer for each info
    Mixer mixer = AudioSystem.getMixer(infoMixer);
    String mixerName = infoMixer.getName();
    System.out.println("MIXER NAME: " + mixerName);
    System.out.println("MIXER : " + infoMixer.toString());
    System.out.println("MIXER DESC: " + infoMixer.getDescription());

    // Check if is input device
    Line.Info[] lines = mixer.getTargetLineInfo();
    if (lines.length > 0) {
        for (Line.Info line : lines) {
            if (line.getLineClass().equals(TargetDataLine.class)) {
                System.out.println("LINE INFO: " + line.toString());
            }
        }
    }
    // Check if is output device
    lines = mixer.getSourceLineInfo();
    if (lines.length > 0) {
        for (Line.Info line : lines) {
            if (line.getLineClass().equals(SourceDataLine.class)) {
                System.out.println("LINE INFO: " + line.toString());
            }
        }
    }
}

如何列出与Ubuntu使用的相同名称的设备?

How can I list my devices with the same names used by Ubuntu?

推荐答案

超过4年后:

System.out.println(String.format("Name [%s]\n", line.getName()));

这篇关于使用Java在Ubuntu中获取音频设备名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆