我有两个类似的波(类似的格式),我用这段代码预加载它们
Clip click1;
Clip click2;
File soundFile = new File("click1.wav");
AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);
DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
click1 = (Clip) AudioSystem.getLine(info);
click1.open(sound);
soundFile = new File("click2.wav");
sound = AudioSystem.getAudioInputStream(soundFile);
info = new DataLine.Info(Clip.class, sound.getFormat());
click2 = (Clip) AudioSystem.getLine(info);
click2.open(sound);
第一个文件被加载,但第二个文件抛出异常:
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:492)
at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1278)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:107)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1059)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1149)
我尝试在 click2 的剪辑上设置 click1.wav,但我遇到了同样的错误。
我有 Ubuntu 11.04,这是 java -version 的结果
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode
编辑
这是 DataLine.Info 的 System.out.println 的结果
click1 = interface Clip 支持格式 PCM_SIGNED 11025.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian
click2 = interface Clip 支持格式 PCM_SIGNED 11025.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian