【发布时间】:2018-02-18 18:06:09
【问题描述】:
我目前有这个代码,它成功记录了一个(mp3-)流:
public class Recorder {
private static final int BUFFER_SIZE = 2048;
private Thread thread;
private boolean running = false;
public Recorder(URL stream, File dest) {
thread = new Thread(() -> {
try {
URLConnection connection = stream.openConnection();
InputStream inStream = connection.getInputStream();
OutputStream outStream = new FileOutputStream(dest);
byte[] buffer = new byte[BUFFER_SIZE];
int length;
System.out.println("Now recording " + stream.toString());
while ((length = inStream.read(buffer)) > 0 && running) {
outStream.write(buffer, 0, length);
}
outStream.close();
} catch (IOException e) {
e.printStackTrace();
}
});
}
public void start() {
running = true;
thread.start();
}
public void stop() {
running = false;
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
如何正确读取流中的 MP3 标签(歌曲名称和艺术家姓名)?我找到了一些关于如何从文件中获取 MP3 标记的答案,但不是从流音频中获取。
谢谢。
【问题讨论】:
标签: java audio io streaming mp3