I'm having issues with parsing the data from an mp3 file based on it's bytes.
The first part the output is correct, I have an mp3 file that is 254 seconds long and I obtain its information from the mp3 parsing library mp3agic from Github.
However, the second part of the information, regarding frame length and duration is incorrect.
Length of this mp3 is: 254 seconds
Bitrate: 320 kbps (CBR)
Sample rate: 44100 Hz
Has ID3v1 tag?: NO
Has ID3v2 tag?: YES
Has custom tag?: NO
framelength -1
framerate 38.28125
duration -271265.06
The code that I use to get framelength, framerate and duration is:
File file = musicFile.getFileValue();
this.audioStream.startMusicStream(file);
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
AudioFormat format = audioInputStream.getFormat();
long audioFileLength = file.length();
int frameSize = format.getFrameSize();
float frameRate = format.getFrameRate();
float durationInSeconds = (audioFileLength / (frameSize * frameRate));
System.out.println("framelength "+frameSize);
System.out.println("framerate "+frameRate);
System.out.println("duration "+durationInSeconds);
this.setDurationLabel(durationInSeconds);
} catch (Exception e) {
e.printStackTrace();
}
Fist of all, why is framelength and the other measurements even negative? What does that even mean? And how can I accurately calculate the duration of an mp3 file using the information from the audioinputstream and audioformat?