Tariq
Tariq

Reputation: 155

How to read/write mp3 (origin) tags using jaudiotagger java

I have successfully read/write mp3 tags ARTIST, TITLE, COMPOSER using jaudiotagger. I also want to read/write origin mp3 tags like PUBLISHER, ENCODED BY, AUTHOR URL, COPYRIGHT AND SUBTITLE.

here is my java code

AudioFile f = (MP3File) AudioFileIO.read(new File(filePath));
audioTag = f.getTag();
audioTag.setField(FieldKey.TITLE, "JAudioTagger");
f.commit();
audioTag.getFirst(FieldKey.TITLE);

Can anyone know how to achieve these tags ?

Upvotes: 0

Views: 1223

Answers (1)

Paul Taylor
Paul Taylor

Reputation: 13120

The field names you have listed aren't actually Mp3 fields, however with the FieldKey class we map commonly used fieldnames to the correct mp3 frame so you can access three of them as follows

audioTag.setField(FieldKey.LABEL, "Publisher");
audioTag.setField(FieldKey.URL_OFFICIAL_ARTIST_SITE, "AuthorUrl");
audioTag.setField(FieldKey.SUBTITLE, "Subtitle");

To write copyright you currently have to use the mp3 specific interface to write the copyright (TCOP frame)

e.g

 Mp3File f = (Mp3File) AudioFileIO.read(new File(filePath));
 Tag audioTag = f.getTag();
 ID3v23Frame frame = new ID3v23Frame("TCOP");
 frame.setBody(new FrameBodyTCOP(TextEncoding.ISO_8859_1,"copyright"));
 tag.addFrame(frame);
 f.commit();

and for encode by we use the same method to write to the TENC frame.

 Mp3File f = (Mp3File) AudioFileIO.read(new File(filePath));
 Tag audioTag = f.getTag();
 ID3v23Frame frame = new ID3v23Frame("TENC");
 frame.setBody(new FrameBodyTENC(TextEncoding.ISO_8859_1,"encode by"));
 tag.addFrame(frame);
 f.commit();

Upvotes: 1

Related Questions