开发者

Java code that determines the headers in an mp3 file

I've been writing a program that can determine any and every data about an mp3 file. Based on the info on this webpage (http://www.multiweb.cz/twoinches/mp3inside.htm), my program reads the whole mp3 file into a byte array, then checks for Tag v2 at the start and Tag v1 at the end of the file.

My problem is with the data that you can get from the headers. As far as I understand, I need to search for bytes that are 1111_1111 and the next one is 111x_xxxx. There are a fair few matches for this criteria that aren't headers, just random coincidence, so I've made an MP3Header class, that has all the fields mentioned on the above webpage (ID, layer, bitrate etc..) and overriden the equals method to return true if ID, layer, and frequency match(I use the first header that I find as the base, and compare every other one after it to that one).

This method seems to work perfectly for CBR mp3 files, however some VBR ones are giving me a hard time. The first header I find is incorrect, and from that point on, the whole comparison is screwed (I'm not checking bitrate for equality so that can't be the reason). The only valid explanati开发者_Go百科on I can come up with, is that the Tag at the start may contain characters from the extended ASCII table, and since Java doesn't have unsigned int, a 1111_1111 (255) byte might be interpreted as -1 when converted to int. My question is, how can I make sure that the bytes I find are indeed a proper header? Or should I store everything that matches the criteria, and check which one is the most frequent, and go with that?

Thanks, István

P.S: I know this could probably be solved with only a few lines of code if I used JMF, however I'm enjoying the challenge of writing it like this.


I understand there are libraries already available that perform this task (see https://id3.org/Implementations). Perhaps you could download the source and see how they do it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜