gpt4 book ai didi

java - 如何阅读 MP3

转载 作者:行者123 更新时间:2023-11-30 08:01:52 25 4
gpt4 key购买 nike

使用this post我能够找到如何读取 mp3 文件,但我仍然对如何实际使用它感到困惑。

File file = new File(filename);
AudioInputStream in= AudioSystem.getAudioInputStream(file);
AudioInputStream din = null;
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false);
din = AudioSystem.getAudioInputStream(decodedFormat, in);

在这些声明之后,如何使用din?我知道循环看起来像这样:

while (/*What do I put here??*/){
int currentByte = din.read();
}

换句话说,我只是问如何从 mp3 文件中读取整个字节数组,并在循环中一次检查一个字节。

最佳答案

AudioInputStream.read() returns -1 when it's out of data ,这样您就可以在发生这种情况时中断循环:

while (true){
int currentByte = din.read();
if (currentByte == -1) break;
// Handling code
}

关于java - 如何阅读 MP3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31797500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com