我试图使用下面的代码获取 MAC OSX 中可用的混合物。尽管我连接了 3 个不同的音频设备,并且能够在系统声音设置中看到相同的内容,但下面的代码并未显示全部。即 mix.getMixerInfo()).isLineSupported(info) 不允许显示任何内容并且 甚至无法使用 java 连接。 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());
}
}
}
输出:
Mixture Java Sound 音频引擎
混合内置输入
混合 JABRA TALK
混合罗技 USB 耳机
支持的混合::Java Sound 音频引擎
这是 mac osx 中声音 API 的限制吗?还是有其他方法可以在 mac 中做到这一点?
最佳答案
此问题是针对 OS X 2014-001 的 Apple Java 遇到的。从苹果卸载了java 1.6并尝试使用oracle java 1.7。现在这在 mac osx 和 windows 上都工作得很好。
关于java - 如何在 mac osx 中使用 java 获取连接的可用音频设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25397227/