Note that there are some explanatory texts on larger screens.

plurals
  1. POJava/JAudiotagger: Mp3 wrong ID3 tag size
    text
    copied!<p>I'm building an mp3 tagging application using the <a href="http://www.jthink.net/jaudiotagger/index.jsp" rel="nofollow noreferrer">JAudiotagger</a> library. My application reads the mp3 metadata fine, and can write the metadata fine too, <em>except for the artworks</em>. So my problem is as follows:</p> <p>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, <em>the file size doesn't get smaller</em>. <p>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.</p> <p><p>The method I'm using when deleting an artwork is this:</p> <pre><code> // Get the artworkList from the parentFrame. List&lt;Artwork&gt; 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&lt;Artwork&gt; iterator = list.iterator(); while (iterator.hasNext()) { try { tag.addField(iterator.next()); } catch (FieldDataInvalidException e1) { e1.printStackTrace(); } } } </code></pre> <p>, 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.</p> <p><p>My attempts for a solution were:</p> <ul> <li><p>To create a new tag from the updated old tag (after calling <code>tag.deleteArtworkField()</code>), then adding the artworks to the new tag, but the new tag had the same size as the old one.</p></li> <li><p>To trim the mp3 file just before saving it by using <code>tag.adjustPadding(File fileToBeTrimmed, int sizeToStoreTagBeforeAudioInBytes, long audioStartByte)</code>, which adjusts the length of the padding at the beginning of the MP3 file. <br>The problem here is that I know the wrong tag size only and not the correct, so I can't trim the mp3 correctly and I end up losing audio data.</p></li> </ul> <p><p>To illustrate the problem better I have included some images:</p> <p><p>The mp3 file before:</p> <p><p><a href="http://imageshack.us/a/img694/3766/mp3filebefore.jpg" rel="nofollow noreferrer">before http://imageshack.us/a/img694/3766/mp3filebefore.jpg</a></p> <p><p>The mp3 file after the removal of one artwork. Notice the tag kept its previous size although it has less artworks:</p> <p><p><a href="http://imageshack.us/a/img513/2476/mp3fileafterwrong.jpg" rel="nofollow noreferrer">after wrong http://imageshack.us/a/img513/2476/mp3fileafterwrong.jpg</a></p> <p><p> And how the file should be:</p> <p><p><a href="http://imageshack.us/a/img818/1506/mp3fileaftercorrect.jpg" rel="nofollow noreferrer">after correct http://imageshack.us/a/img818/1506/mp3fileaftercorrect.jpg</a></p> <p><p>I hope anyone has any ideas. Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload