Search code examples
javamp3mp3agic

Change album names using mp3agic


I wanted to loop through a folder containig .mp3 files and changing their album names (if they don't have one) to their title (e.g. Remix.mp3 with Title "Remix" gets the Album "Remix") using mp3agic.

This is my code so far:

if (mp3file.hasId3v1Tag()) {
    ID3v1 id3v1Tag = mp3file.getId3v1Tag();

    try {
        if (id3v1Tag.getAlbum().equals("")) {
            id3v1Tag.setAlbum(id3v1Tag.getTitle());
            mp3file.save(SAVE_DIR + "\\" + child.getName());
            System.out.println(SAVE_DIR + "/" + child.getName());
        } else {
            mp3file.save(SAVE_DIR + "/" + child.getName());
        }
    } catch (Exception e) {
        mp3file.save(SAVE_DIR + "/" + child.getName());
    }
}

I get the following error:

Exception in thread "main" com.mpatric.mp3agic.NotSupportedException: Packing Obselete frames is not supported at com.mpatric.mp3agic.ID3v2ObseleteFrame.packFrame(ID3v2ObseleteFrame.java:32) at com.mpatric.mp3agic.ID3v2Frame.toBytes(ID3v2Frame.java:83) at com.mpatric.mp3agic.AbstractID3v2Tag.packSpecifiedFrames(AbstractID3v2Tag.java:275) at com.mpatric.mp3agic.AbstractID3v2Tag.packFrames(AbstractID3v2Tag.java:261) at com.mpatric.mp3agic.AbstractID3v2Tag.packTag(AbstractID3v2Tag.java:227) at com.mpatric.mp3agic.AbstractID3v2Tag.toBytes(AbstractID3v2Tag.java:218) at com.mpatric.mp3agic.Mp3File.save(Mp3File.java:450) at de.thejetstream.main.Iterator.(Iterator.java:57) at de.thejetstream.main.Main.main(Main.java:12)

at this file:

name: Feel Good in Black and Yellow.mp3

title: Feel Good in Black and Yellow (feat. Gorillaz & De La Soul)

album: Black and Yellow - Single

It crashes at line 57, which equals to the last save (in the catch).

What is the problem with this code? Is it just because the file uses an old kind of codec or something like this?


Solution

  • I found the solution:

    The problem was that these files used ip3v2 tags instead of ip3v1. Simply checking which on it is and adjusting the code accordingly solved everything.