I'm relatively new to Java programming. Here i'm trying to use Jaudiotagger library for altering/creating new ID3 tag for mp3s without one in one of my android project. However, I really cannot set to made the library work correctly. That is, For mp3s with some ID3 tag already set, I can successfully write and change the metadata without any problems. But for those mp3s who has no ID3 tag set (blank), I can only manage to set the album cover artwork and other fields like artist, title, album cover, etc remain blank as before.
Here is a snippet of my code -
import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.TagOptionSingleton;
import org.jaudiotagger.tag.id3.ID3v23Tag;
import org.jaudiotagger.tag.images.Artwork;
import org.jaudiotagger.tag.images.ArtworkFactory;
try{
TagOptionSingleton.getInstance().setAndroid(true);
AudioFile f =AudioFileIO.read(file_path_to_mp3);
f.setTag(new ID3v23Tag());
Tag tag=f.getTag();
tag.setField(FieldKey.ARTIST,artist);
tag.setField(FieldKey.ALBUM,album);
Artwork cover=ArtworkFactory.createArtworkFromFile(cover_file);
tag.setField(cover);
f.commit();
}catch (Exception e){
e.printStackTrace();
}
I can run the program without getting any error and exception thrown. Just that the matadata tag like title, artist, album etc wont set though the artwork can be set successfully. Thanks for any help!
I write some code to help you change the data of the mp3 file