File sourceFile; MP3File mp3file = new MP3File(sourceFile);You can also read specific tags:
ID3v1_1 tag = new ID3v1_1(sourceFile); ID3v1 tag = new ID3v1(sourceFile); ID3v2_4 tag = new ID3v2_4(sourceFile); ID3v2_3 tag = new ID3v2_3(sourceFile); ID3v2_2 tag = new ID3v2_2(sourceFile); Lyrics3v2 tag = new Lyrics3v2(sourceFile); Lyrics3v1 tag = new Lyrics3v1(sourceFile);
MP3File mp3file = new MP3File(); TagOptionSingleton.getInstance().setDefaultSaveMode(TagConstant.MP3_FILE_SAVE_OVERWRITE); // setup 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:
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);
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");
mp3file.save();You can also save each individual tag through each tags' save() method.
Field Name | ID3v1 | ID3v1.1 | ID3v2.2 | ID3v2.3 | ID3v2.4 | Lyrics3v1 | Lyrics3v2 |
Song Title | title | title | TT2 | TIT2 | TIT2 | -- | ETT |
Lead Artist | artist | artist | TP1 | TPE1 | TPE1 | -- | EAR |
Album Title | album | album | TAL | TALB | TALB | -- | EAL |
Year Released | year | year | TYE | TYER | TDRC | -- | -- |
Comment | comment | comment | COM | COMM | COMM | -- | INF |
Song Genre | genre | genre | TCO | TCON | TCON | -- | -- |
Track number on album | -- | track | TRK | TRCK | TRCK | -- | -- |
Lyrics | -- | -- | SYL or ULT | SYLT or USLT | SYLT or USLT | lyric | LYR |
Author / Composer | -- | -- | TCM | TCOM | TCOM | -- | AUT |