1

I realize it would be easier to use a library like mp3agic or jaudiotagger but I wanted to edit id3 tags manually for learning purposes.

I have code set up to get the tags properly, however I noticed that for some songs the title is cut at 30 characters however when I open the .mp3 file in a music player the full title is shown, which is longer than 30 characters.

This is the code that I'm using right now to view the tags:

            File mp3File = new File(filePath);

            byte[] mp3Meta = new byte[128];

            try {
                //convert file into array of bytes
                fileReader = new FileInputStream(mp3File);
                fileReader.skip((int)mp3File.length() - 128);
                fileReader.read(mp3Meta);
                String id3 = new String(mp3Meta); 

                String tag = id3.substring(0, 3); 
               if (tag.equals("TAG")) {
                System.out.println("\nTitle: " + id3.substring(3, 32) + "\n" +
                    "Artist: " + id3.substring(33, 62) + "\n" +
                    "Album: " + id3.substring(63, 91) + "\n" +
                    "Year: " + id3.substring(93, 97) + "\n" +
                    "************************************************");
               } else {
                System.out.println("File has no ID3 tags..");
               }
            }catch(Exception e){
                e.printStackTrace();
            }

I have an idea as to how I can edit the tags, but how can I get the full title (or any tag) if it's longer than 30 characters? I read there was a way to add a tag longer than 30 characters in id3v2 but I'm not sure how to access id3v2 frames

I believe I have to determine which version (id3v1 or id3v2) the mp3 is using, but I'm not sure how to do that programmatically either.

Brian
  • 11
  • 3
  • 1
    ID3 is, as you say, limited to 30 character titles. To read/store more characters, you'll need to use ID3v2. – dnault Apr 25 '16 at 21:41
  • dnault- Do you know how I can go about doing so? I've read through the page found at http://id3.org/ID3v2Easy but I'm not sure how much offsetting needs to be done or the specific byte location for each tag. – Brian Apr 25 '16 at 22:20
  • How the identify the ID3-Version: "If you one sum the the size of all these fields we see that 30+30+30+4+30+1 equals 125 bytes and not 128 bytes. The missing three bytes can be found at the very beginning of the tag, before the song title. These three bytes are always "TAG" and is the identification that this is indeed a ID3 tag. The easiest way to find a ID3v1/1.1 tag is to look for the word "TAG" 128 bytes from the end of a file." Source: http://id3.org/ID3v1 – PeterCo Apr 26 '16 at 10:09
  • PeterCo, yes thats is what im using currently in my code. But how can i go about finding an ID3v2 tag instead of a ID3v1? – Brian Apr 26 '16 at 12:23
  • I can't help you with Java. One important difference: ID3v2 tags usually occur at the start of the file, ID3v1 tags at the end. Maybe you should look inside the code of one of the many existing implementations at http://id3.org/Implementations – PeterCo Apr 27 '16 at 10:01

2 Answers2

0

I know this is an old question and that you've probably figured things out by now, but I thought I'd answer in more detail for anyone who comes across this question with any similar problem.

ID3v1 (which may sometimes just be called "ID3") is a short, structured data block located at the end of the file. ID3v2 tags – in all revisions – are comprised of many optional "fields" that can typically be any (reasonable) length, in any order, and are located at the beginning of the file. As far as I can tell, the only reason they have a similar name is because they're added to the same type of file. Anything written to parse/update one version will have no idea what to do with the other.

As the original question demonstrates, ID3v1 is particularly simple to read; the biggest part of any full implementation will be the genre lookup table. ID3v2 (whether revision 2.3 or 2.4), as befitting its greater power, is decidedly not. I'd actually recommend it as a mid-level exercise in either understanding metadata or learning to implement specifications, but for any program where you just want to use the data, it would be much better to just reference one of the prebuilt libraries. Unfortunately, I don't know enough about the Java implementations to recommend one, but look around a bit and you'll find plenty of discussions about them.

Sam May
  • 58
  • 5
0

Before ID3v2 was born there was an unofficial "Enhanced TAG"/"ID3 Extended"/"TAG+" to add 60 more bytes to almost all ID3v1 fields (without redundancy). See https://web.archive.org/web/20120310015458/http://www.fortunecity.com/underworld/sonic/3/id3tag.html and https://phoxis.org/2010/05/08/what-are-id3-tags-all-about/#id3v1ext

Another semi-official standard was "Lyrics3" version 2.00 which is able to store 250 bytes for almost every ID3v1 field (being redundant). See http://id3.org/Lyrics3v2

AmigoJack
  • 5,234
  • 1
  • 15
  • 31