【发布时间】:2014-11-16 15:32:41
【问题描述】:
我想从 Internet 流式传输音频文件并播放它。 我正在使用此代码:
int readBytes = 0;
byte[] audioBuffer = new byte[this.EXTERNAL_BUFFER_SIZE];
readBytes = in.read(audioBuffer, 0, audioBuffer.length);
while (readBytes != -1) {
readBytes = in.read(audioBuffer, 0, audioBuffer.length);
if (readBytes >= 0) {
dataLine.write(audioBuffer, 0, readBytes);
}
}
这样做的问题是,当 Stream 正在读取时,它不是在写入。因此,音乐不会每隔几秒钟播放很短的时间。 所以我想知道是否有一种方法可以让流同时从输入流中读取并写入数据线,这样写入就不会暂停读取。
【问题讨论】: