p id3v1 id3v1.setAlbum("albumTitle");
// setup id3v2 AbstractID3v2Frame frame; AbstractID3v2FrameBody frameBody; frameBody = new FrameBodyTALB((byte) 0, "albumTitle"); frame = new ID3v2_4Frame(frameBody); id3v2.setFrame(frame);
// setup lyrics3v2 Lyrics3v2Field field; AbstractLyrics3v2FieldBody fieldBody; fieldBody = new FieldBodyEAL("albumTitle"); field = new Lyrics3v2Field(fieldBody); lyrics3.setField(field);
// setup filename tag frameBody = new FrameBodyTALB((byte) 0, "albumTitle"); frame = new ID3v2_4Frame(frameBody); filenameId3.setFrame(frame); TagOptionSingleton.getInstance().setFilenameTagSave(true); Things to note:
- The default save mode is "write but do not delete." This means each field in the object will be saved, but existing fields in the file on disk will not be deleted. The other two are "only append" or "delete and write from scratch."
Editing Part 1:
There are convience methods defined in AbstractMP3Tag to edit common data fields. Not all tags have all fields listed here.
public abstract String getSongTitle(); public abstract String getLeadArtist(); public abstract String getAlbumTitle(); public abstract String getYearReleased(); public abstract String getSongComment(); public abstract String getSongGenre(); public abstract String getTrackNumberOnAlbum(); public abstract String getSongLyric(); public abstract String getAuthorComposer(); public abstract void setSongTitle(String songTitle); public abstract void setLeadArtist(String leadArtist); public abstract void setAlbumTitle(String albumTitle); public abstract void setYearReleased(String yearReleased); public abstract void setSongComment(String songComment); public abstract void setSongGenre(String songGenre); public abstract void setTrackNumberOnAlbum(String trackNumberOnAlbum); public abstract void setSongLyric(String songLyrics); public abstract void setAuthorComposer(String authorComposer);
Editing Part 2:
If the field you want is not listed above, you can use these methods.
id3v1 = mp3file.getID3v1Tag(); id3v2 = mp3file.getID3v2Tag(); lyrics3 = mp3file.getLyrics3Tag();
ID3v1 tags have fixed fields and use accessor methods to change it's properties.
ID3v2 tags have multiple frames. Use this to set the title of the tag.
frame = id3v2.getFrame("TIT2"); ((FrameBodyTIT2) frame.getBody()).setText("New Title");
Lyrics3 tags have multiple fields. Use this to set the title of the tag.
field = lyrics3.getField("ETT"); ((FieldBodyETT) field.getBody()).setTitle("New Title");
Writing:
mp3file.save();
You can also save each individual tag through each tags' save() method.
@author Eric Farng
@version $Revision: 1.4 $