我的毕业设计中有一个声音录制传输且要在那一边还原回来的一个模块,我写倒是写出来了,没有用JFM,写的是应用程序,也能跟踪得到发出的数据和接收的数据是一样的,可就是听不到声音,各位高手帮忙看看吧!播放线程如下:
class PlayThread extends Thread {
byte[] byteSound;
SourceDataLine sourceLine;
AudioInputStream newSource;
InputStream inputStream;
AudioInputStream soundStream;
int MONO = 1;
AudioFormat format = new AudioFormat(AudioFormat.Encoding.
PCM_UNSIGNED,
8000, 8, MONO, 1, 8000, false);
int bufferSize;
byte[] soundData;
int byteCount = 0;public PlayThread(byte[] RecData, SourceDataLine sourceDataLine) {
byteSound = RecData;
sourceLine = sourceDataLine;
inputStream = new ByteArrayInputStream(byteSound);
newSource = new AudioInputStream(inputStream, format,
byteSound.length / format.getFrameSize());
bufferSize = (int) (format.getFrameSize() * format.getFrameRate() /
2.0f);
soundData = new byte[bufferSize];
}public void run() {
sourceLine.start();
try {
while (true) {
byteCount = newSource.read(soundData, 0, soundData.length);
if (byteCount == -1) {
if (newSource.Supported()) {
newSource.reset();
}
sourceLine.drain();
break;
}
sourceLine.write(soundData, 0, byteCount);
}
} catch (IOException e) {
System.err.println(e);
}
sourceLine.stop();
}
}