Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何阅读MP3_Java_Mp3 - Fatal编程技术网

Java 如何阅读MP3

Java 如何阅读MP3,java,mp3,Java,Mp3,使用我能够找到如何阅读mp3文件,但我仍然对如何实际使用它感到困惑 File file = new File(filename); AudioInputStream in= AudioSystem.getAudioInputStream(file); AudioInputStream din = null; AudioFormat baseFormat = in.getFormat(); AudioFormat decodedFormat = new AudioFormat(AudioForma

使用我能够找到如何阅读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(),这样在发生这种情况时,您就可以中断循环:

while (true){
    int currentByte = din.read();
    if (currentByte == -1) break;
    // Handling code
}
请尝试以下代码: 导入java.io.DataInputStream; 导入java.io.FileInputStream

public class Main {

  public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("C:/Array.txt");
    DataInputStream din = new DataInputStream(fin);

    byte b[] = new byte[10];
    din.read(b);
    din.close();
  }
提供人: