javamp3id3id3-tagid3v2

Java/JAudiotagger: Mp3 wrong ID3 tag size


I'm building an mp3 tagging application using the JAudiotagger library. My application reads the mp3 metadata fine, and can write the metadata fine too, except for the artworks. So my problem is as follows:

When I add a number of artworks in the mp3 file, and save it, the file is getting bigger, which makes sense. But when I remove one or all the artworks, the file size doesn't get smaller.

The actual problem lies in the ID3v2 tag of my mp3 file. When I remove an artwork, it is actually removed from the tag, but the tag size itself doesn't shrink at all.

The method I'm using when deleting an artwork is this:

    // Get the artworkList from the parentFrame.
    List<Artwork> list = parentFrame.getArtworkList();

    // Get the tag from the parentFrame's mp3File.
    AbstractID3v2Tag tag = parentFrame.getTag();

   // Get the index of the artwork the user is currently looking at (and
   // wants to delete too).
   int visibleArtworkIndex = parentFrame.getVisibleArtworkIndex();

   // Remove it from the list.
   list.remove(visibleArtworkIndex);

   // Update the parentFrame's copy of the artworkList.
   parentFrame.setArtworkList(list);

   // Update the tag (delete its whole artwork field).
   tag.deleteArtworkField();

   // If the list has more artworks left, add them to the tag.
   if (!list.isEmpty()) {
       Iterator<Artwork> iterator = list.iterator();
       while (iterator.hasNext()) {
           try {
               tag.addField(iterator.next());
           } catch (FieldDataInvalidException e1) {
               e1.printStackTrace();
           }
       }
   }

, which actually removes an artwork from the list, and then updates the tag itself by deleting all of its artworks and copying them all over again from the updated list.

My attempts for a solution were:

To illustrate the problem better I have included some images:

The mp3 file before:

before

The mp3 file after the removal of one artwork. Notice the tag kept its previous size although it has less artworks:

after wrong

And how the file should be:

after correct

I hope anyone has any ideas. Thanks in advance.


Solution

  • This is fixed as of today.

    By default jaudiotagger does not reclaim space when you make the metadata smaller, but now if you set

    TagOptionSingleton.getInstance().setId3v2PaddingWillShorten(true);
    

    before saving changes it will reclaim unnecessary padding to give the minimum file size possible.