【发布时间】:2014-02-19 07:58:40
【问题描述】:
我编写了一个代码来读取 WAV 文件(大小约为 80 mb)并播放它。问题是声音播放不好(极度滞后)。你能告诉我有什么问题吗?
这是我的代码:
(我在 Jframe 构造函数中调用 doPlay 函数)
private void doPlay(final String path) {
try {
stopPlay();
InputStream is = new FileInputStream(path);
InputStream bufferedIn = new BufferedInputStream(is);
AudioInputStream ais = AudioSystem.getAudioInputStream(bufferedIn);
AudioFormat format = ais.getFormat();
// this is the value of format.
// PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
DataLine.Info info = new DataLine.Info(Clip.class, format);
clip = (Clip)AudioSystem.getLine(info);
clip.open(ais);
clip.start();
} catch (Exception e) {
stopPlay();
e.printStackTrace();
}
}
【问题讨论】: