简体   繁体   English

如何在Mac OS X中使用Java连接可用的音频设备

[英]how get available audio devices connected using java in mac osx

i was trying to get the available mixtures in MAC OSX using the below code. 我试图使用以下代码在MAC OSX中获得可用的混合物。 Even though i connected 3 different audio device, and able to see the same in system sound settings,below code doesn't display all. 即使我连接了3种不同的音频设备,并且能够在系统声音设置中看到相同的声音,下面的代码也无法全部显示。 ie mix.getMixerInfo()).isLineSupported(info) is not allowing to display anything and even not able to connect using java . 即mix.getMixerInfo())。isLineSupported(info)不允许显示任何内容,甚至无法使用java连接。 The same is working fine with windows version. Windows版本也一样。

  public static void main(String[] args) {
    String sf_ringtone = "/Users/abc.WAV";
    AudioInputStream stream = null;

    try {
        stream = AudioSystem.getAudioInputStream(new File(sf_ringtone));
    } catch (UnsupportedAudioFileException ex) {
        System.out.println(ex.getStackTrace().toString());
    } catch (IOException ex) {
        System.out.println(ex.getStackTrace().toString());
    }

    AudioFormat format=null;
    format = stream.getFormat();

    if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
        format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                format.getSampleRate(), format.getSampleSizeInBits() * 2,
                format.getChannels(), format.getFrameSize() * 2,
                format.getFrameRate(), true); // big endian
        stream = AudioSystem.getAudioInputStream(format, stream);
    }

    DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat(),
            ((int) stream.getFrameLength() * format.getFrameSize()));

    ArrayList<Mixer> mixerList = (ArrayList<Mixer>) getAllMixer();
    for(Mixer mix:mixerList) {
        System.out.println(" Mixture  "+mix.getMixerInfo().getName());
    }

    ArrayList<String> cmbRingtonePlayback = new ArrayList<String>();
    for (Mixer mix : mixerList) {
        if (AudioSystem.getMixer(mix.getMixerInfo()).isLineSupported(info)) {
            System.out.println(supported mixture :: "+mix.getMixerInfo().getName());                    
        }
    }


}

output: 输出:

Mixture Java Sound Audio Engine 混合Java声音音频引擎

Mixture Built-in Input 混合内置输入

Mixture JABRA TALK 混合物JABRA TALK

Mixture Logitech USB Headset 混合Logitech USB耳机

supported mixture :: Java Sound Audio Engine 支持的混合物:: Java Sound Audio Engine

Is this a limitation of sound API in mac osx ?, or is there any other way to do this in mac? 这是mac osx中声音AP​​I的限制吗?还是在mac中有其他方法可以做到这一点?

This issue faced was with apple Java for OS X 2014-001. Apple Java for OS X 2014-001面临的问题。 Uninstalled java 1.6 from apple and tried with oracle java 1.7. 从Apple卸载Java 1.6,并尝试使用oracle Java 1.7。 Now this is working fine in both mac osx and windows. 现在,这在Mac OS X和Windows中都可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM