Editing MP3 tags

153 Views Asked by At

Does anyone of you know a way to edit the tags of an mp3 file?
I tried Mp3agic but it crash when I try to declare an MP3File object and I also tried tha jaudiotagger library, but it also crashes.

I need help please.

UPDATE:

This is the code snippet where the app crash:

     File testFile = new File(Environment.getExternalStorageDirectory(),"/Music/test.mp3");
        TagOptionSingleton.getInstance().setAndroid(true);

        AudioFile audioFile = AudioFileIO.read(testFile);

        Tag newTag = audioFile.getTag();
        newTag.setField(FieldKey.ALBUM, this.album);
        newTag.setField(FieldKey.ARTIST,this.artist);

        audioFile.commit();

The app crash at the line

AudioFile audioFile = AudioFileIO.read(testFile);

without exception.

By following all debug steps from the aforementioned line, the app crash at line 246 of the MP3File class of JAudioTagger. This is the lines:

..
finally {
        if(newFile != null) {
            newFile.close();
        }

..

So I tried to change my code here (I changed the AudioFile declaration):

File testFile = new File(Environment.getExternalStorageDirectory(),"/Music/test.mp3");
        TagOptionSingleton.getInstance().setAndroid(true);

        AudioFile audioFile = new AudioFile();
        audioFile.setFile(testFile);

        Tag newTag = audioFile.getTag();
        newTag.setField(FieldKey.ALBUM, this.album);
        newTag.setField(FieldKey.ARTIST,this.artist);

        audioFile.commit();

And at line

AudioFile audioFile = new AudioFile();

it throw a NullPointerException at line 232 of MP3File class (the line tries to find the header of the file):

audioFile: Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.jaudiotagger.audio.AudioFile.toString()

This exception cause in the next lines this exception:

java.lang.NullPointerException: Attempt to invoke interface method 'void org.jaudiotagger.tag.Tag.setField(org.jaudiotagger.tag.FieldKey, java.lang.String)' on a null object reference

At line:

newTag.setField(FieldKey.ALBUM, this.album);

UPDATE:

I tried also to change the line:

Tag newTag = audioFile.getTag();

To:

Tag newTag = audioFile.getTagOrCreateAndSetDefault();

But it throw this exception:

java.lang.RuntimeException: Unable to create default tag for this file format
0

There are 0 best solutions below